From 0ec2321b63b844c39ab61447e37a9d74cca5af4c Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 27 Aug 2022 12:45:45 -0400
Subject: [PATCH 001/129] New feature for Prestige: Force a sellall before
processing the prestige. This prevents the player from stashing a ton of
high-value blocks in their inventory before prestiging.
---
docs/changelog_v3.3.x.md | 8 ++++-
.../prison/internal/platform/Platform.java | 3 ++
.../tech/mcprison/prison/TestPlatform.java | 5 ++++
.../prison/spigot/SpigotPlatform.java | 29 +++++++++++++++++++
.../spigot/gui/mine/SpigotPlayerMinesGUI.java | 22 ++++++++++++--
prison-spigot/src/main/resources/config.yml | 2 +-
6 files changed, 65 insertions(+), 4 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index abeda4468..78cf697e4 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,13 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13 2022-08-25
+# 3.3.0-alpha.13 2022-08-27
+
+
+
+* **New feature for Prestige: Force a sellall before processing the prestige.**
+This prevents the player from stashing a ton of high-value blocks in their inventory before prestiging.
+This will not prevent the player from stashing blocks elsewhere.
**3.3.0-alpha.13 2022-08-25**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java b/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
index c82d190d4..ef04889de 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
@@ -444,4 +444,7 @@ public void autoCreateMineLinerAssignment( List rankMineNames,
public void listAllMines(CommandSender sender, Player player);
+
+ public void sellall(RankPlayer rankPlayer);
+
}
diff --git a/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java b/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
index ca8897c18..92bcd6c7f 100644
--- a/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
+++ b/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
@@ -506,4 +506,9 @@ public void checkPlayerDefaultRank( RankPlayer rPlayer ) {
public void listAllMines(CommandSender sender, Player player) {
}
+
+ @Override
+ public void sellall( RankPlayer rankPlayer ) {
+
+ }
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index 9e945d4da..d79de3cc3 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -19,6 +19,7 @@
package tech.mcprison.prison.spigot;
import java.io.File;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -121,6 +122,7 @@
import tech.mcprison.prison.spigot.placeholder.SpigotPlaceholders;
import tech.mcprison.prison.spigot.scoreboard.SpigotScoreboardManager;
import tech.mcprison.prison.spigot.sellall.SellAllBlockData;
+import tech.mcprison.prison.spigot.sellall.SellAllUtil;
import tech.mcprison.prison.spigot.spiget.BluesSpigetSemVerComparator;
import tech.mcprison.prison.spigot.util.ActionBarUtil;
import tech.mcprison.prison.spigot.util.SpigotYamlFileIO;
@@ -2905,4 +2907,31 @@ private void listMines(tech.mcprison.prison.internal.CommandSender sender,
}
+ @Override
+ public void sellall( RankPlayer rankPlayer ) {
+
+ if ( SpigotPrison.getInstance().isSellAllEnabled() ) {
+
+ Player player = getPlayer( rankPlayer.getUUID() ).orElse(null);
+
+ if ( player != null ) {
+
+ SpigotPlayer sPlayer = (SpigotPlayer) player;
+
+ final long nanoStart = System.nanoTime();
+ boolean success = SellAllUtil.get().sellAllSell( sPlayer.getWrapper(),
+ false, false, false, true, true, false);
+ final long nanoStop = System.nanoTime();
+ double milliTime = (nanoStop - nanoStart) / 1000000d;
+
+ if ( Output.get().isDebug() ) {
+
+ DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ Output.get().logDebug( "(SpigotPlatform autosell: " + (success ? "success" : "failed") +
+ " ms: " + dFmt.format( milliTime ) + ") ");
+ }
+
+ }
+ }
+ }
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
index 6967f8c0d..0f232118f 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
@@ -128,12 +128,30 @@ public void open() {
// Add mineName lore for TP.
minesLore.addLineLoreAction( "&3" + mineName );
+
+ boolean hasMineAccess = m.hasMiningAccess(spigotPlayer);
+ String permMineAccess = permission + m.getName();
+ boolean hasPermMine = p.hasPermission( permMineAccess );
+ String permAccess = permission.substring(0, permission.length() - 1);
+ boolean hasPerm = p.hasPermission( permAccess );
// If the player has permission to access the mine, then see if there is a custom
// block set for the mine... otherwise it will use XMaterial.COAL_ORE:
- if (m.hasMiningAccess(spigotPlayer) || p.hasPermission(permission + m.getName()) ||
- p.hasPermission(permission.substring(0, permission.length() - 1)))
+ if ( hasMineAccess ||
+ hasPermMine ||
+ hasPerm )
{
+
+ if ( !hasMineAccess ) {
+ Output.get().logInfo(
+ "GUI Player Mines: Has access to mine %s through perms: %s=%s OR %s=%s",
+ m.getName(),
+ permMineAccess, Boolean.toString(hasPermMine),
+ permAccess, Boolean.toString(hasPerm)
+ );
+ }
+
+
// Default to COAL_ORE since the player has access to the mine:
xMat = XMaterial.COAL_ORE;
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index a7b6c7414..8849423c5 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -53,6 +53,7 @@ prestige:
resetDefaultLadder: true
confirmation-enabled: true
prestige-confirm-gui: true
+ force-sellall: false
@@ -141,7 +142,6 @@ top-stats:
hesitancy-delay-penalty: true
-# NEW:
# Prison mines reset gap is the number of milliseconds that are used to
# space out the mine resets when starting the server. This value should
# not be changed unless you understand what you are doing. This value
From 6bf7ce8c5319c8f48ec4e87733f3e2ded6a1054a Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 27 Aug 2022 13:18:47 -0400
Subject: [PATCH 002/129] Enable access to prior mines, or prevent access to
prior mines, based upon the player's rank. See
`prison-mines.access-to-prior-mines` in config.yml
---
docs/changelog_v3.3.x.md | 3 +++
docs/knownissues_v3.3.x.md | 5 +++-
.../prison/ranks/data/RankPlayer.java | 25 +++++++++++++++----
.../prison/ranks/commands/RankUpCommand.java | 7 ++++++
prison-spigot/src/main/resources/config.yml | 2 +-
5 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 78cf697e4..0a950f460 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -15,6 +15,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13 2022-08-27
+* **Enable access to prior mines, or prevent access to prior mines, based upon the player's rank.**
+See `prison-mines.access-to-prior-mines` in config.yml
+
* **New feature for Prestige: Force a sellall before processing the prestige.**
This prevents the player from stashing a ton of high-value blocks in their inventory before prestiging.
diff --git a/docs/knownissues_v3.3.x.md b/docs/knownissues_v3.3.x.md
index b736e0fe2..7b2d98a5d 100644
--- a/docs/knownissues_v3.3.x.md
+++ b/docs/knownissues_v3.3.x.md
@@ -9,6 +9,7 @@
- In the GUI menu, the config setting: Enchantment_effect_current_rank is off by 1. If D rank it shows E being unlocked. - CITYJD
+- DONE: Force sellall before prestiges - kikiisyourfriend
- Add `*all*` to `/mines set notification` - CITYJD
@@ -17,8 +18,10 @@
- Auto-Forced-Rankups and prestiges when the player has enough money. Kikiisyourfriend
- a new autoFeatures entry
-- Enable Access to prior mines - kikiisyourfriend
+
+- DONE: Enable Access to prior mines - kikiisyourfriend
- disable to prevent going back to prior rank mines.
+ - See `prison-mines.access-to-prior-mines` in config.yml
- DONE: prison_rank__linked_mines_rankname prison_r_lm_rankname provide a placeholder for the mine's tags. B0mer
diff --git a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
index cf02b33f4..569cfc680 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
@@ -782,6 +782,13 @@ public void setRanksRefs( HashMap ranksRefs ) {
* it finds a match with the target rank.
*
*
+ *
If the setting prison-mines.access-to-prior-mines is true, as found in the
+ * config.yml file, then prior ranks on the target ladder is search if the
+ * current rank is not a match to the targetRank. Setting this setting to
+ * false will allow admins to use Mine Access by Rank but only for their
+ * current rank.
+ *
+ *
* @param targetRank
* @return
*/
@@ -800,13 +807,21 @@ public boolean hasAccessToRank( Rank targetRank ) {
rank.getLadder().equals( targetRank.getLadder() ) ) {
hasAccess = rank.equals( targetRank );
- Rank priorRank = rank.getRankPrior();
-
- while ( !hasAccess && priorRank != null ) {
+
+ // If access-to-prior-mines is enabled (defaults to true if does not exist),
+ // then search prior ranks on this ladder until a match with target is found.
+ if ( Prison.get().getPlatform()
+ .getConfigBooleanTrue( "prison-mines.access-to-prior-mines" ) ) {
+
+ Rank priorRank = rank.getRankPrior();
- hasAccess = priorRank.equals( targetRank );
- priorRank = priorRank.getRankPrior();
+ while ( !hasAccess && priorRank != null ) {
+
+ hasAccess = priorRank.equals( targetRank );
+ priorRank = priorRank.getRankPrior();
+ }
}
+
}
}
}
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommand.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommand.java
index bfd5072b1..2ce9bacf6 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommand.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommand.java
@@ -267,6 +267,13 @@ private void rankUpPrivate(CommandSender sender, String playerName, String ladde
return;
}
+ // If force sellall, then perform the sellall here:
+ if ( Prison.get().getPlatform().getConfigBooleanFalse( "prestige.force-sellall" ) ) {
+
+ Prison.get().getPlatform().sellall( rankPlayer );
+ }
+
+
// IF everything's ready, this will be true if and only if pRank is not null,
// and the prestige method will start
canPrestige = true;
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 8849423c5..971b77bb9 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -164,7 +164,7 @@ prison-mines:
enabled: false
movementMaxDistance: 1.0
delayInTicks: 20
-
+ access-to-prior-mines: true
# Warning: Do not use the following option. This could break the natural Bukkit
From e8d51ba08f88410795463c15cc0edd42a8e12389 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 29 Aug 2022 20:17:33 -0400
Subject: [PATCH 003/129] New feature: Auto Forced Rankup. When using
autosell, it will auto rankup the player when they have enough money. This
includes both normal /rankup and /prestige. This configuration setting is set
within config.yml in prison-mines.forced-auto-rankups: true.
---
docs/changelog_v3.3.x.md | 7 ++-
.../prison/spigot/SpigotPlatform.java | 3 +
.../spigot/block/OnBlockBreakEventCore.java | 13 +++-
.../commands/PrisonSpigotSellAllCommands.java | 12 ++++
.../spigot/gui/ListenersPrisonManager.java | 9 +++
.../utils/tasks/PlayerAutoRankupTask.java | 62 +++++++++++++++++++
.../utils/tasks/PrisonUtilsTaskTypes.java | 1 +
prison-spigot/src/main/resources/config.yml | 1 +
8 files changed, 106 insertions(+), 2 deletions(-)
create mode 100644 prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PlayerAutoRankupTask.java
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 0a950f460..0627202b9 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,12 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13 2022-08-27
+# 3.3.0-alpha.13 2022-08-29
+
+
+* **New feature: Auto Forced Rankup. When using autosell, it will auto rankup the player when they have enough money.**
+This includes both normal /rankup and /prestige.
+This configuration setting is set within config.yml in prison-mines.forced-auto-rankups: true.
* **Enable access to prior mines, or prevent access to prior mines, based upon the player's rank.**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index d79de3cc3..3bb6503f9 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -126,6 +126,7 @@
import tech.mcprison.prison.spigot.spiget.BluesSpigetSemVerComparator;
import tech.mcprison.prison.spigot.util.ActionBarUtil;
import tech.mcprison.prison.spigot.util.SpigotYamlFileIO;
+import tech.mcprison.prison.spigot.utils.tasks.PlayerAutoRankupTask;
import tech.mcprison.prison.store.Storage;
import tech.mcprison.prison.util.Bounds.Edges;
import tech.mcprison.prison.util.Location;
@@ -2931,6 +2932,8 @@ public void sellall( RankPlayer rankPlayer ) {
" ms: " + dFmt.format( milliTime ) + ") ");
}
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
+
}
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
index 5f8dbed56..ffd69260d 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
@@ -34,6 +34,7 @@
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
import tech.mcprison.prison.spigot.utils.BlockUtils;
+import tech.mcprison.prison.spigot.utils.tasks.PlayerAutoRankupTask;
import tech.mcprison.prison.util.Text;
public abstract class OnBlockBreakEventCore
@@ -692,6 +693,8 @@ else if ( targetExplodedBlock.isMined() ) {
debugInfo.append( "(autosellBLOCKEVENTS: " + (success ? "success" : "failed") +
" ms: " + dFmt.format( milliTime ) + ") ");
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( pmEvent.getSpigotPlayer(), debugInfo );
+
}
String triggered = null;
@@ -988,6 +991,8 @@ public boolean applyDropsBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, int
// calculates the durability, applies food exhaustion:
processBlockBreakage( pmEvent, debugInfo );
+
+// forcedAutoRankups( pmEvent, debugInfo );
// autosellPerBlockBreak( pmEvent.getPlayer() );
@@ -1004,6 +1009,12 @@ public boolean applyDropsBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, int
+// private void forcedAutoRankups(PrisonMinesBlockBreakEvent pmEvent, StringBuilder debugInfo) {
+//
+// PlayerAutoRankupTask.autoSubmitPlayerRankupTask( pmEvent.getSpigotPlayer(), debugInfo );
+//
+// }
+
// /**
// *
This function is processed when auto manager is disabled and process crazy enchant explosions
// * is enabled. This function is overridden in AutoManager when auto manager is enabled.
@@ -1086,7 +1097,7 @@ public boolean applyDropsBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, int
- public void processBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, StringBuilder debugInfo )
+ private void processBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, StringBuilder debugInfo )
{
// If this block is not in the mine (if null) and it has not been broke before
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
index 4c376d10b..c32e0f0cf 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
@@ -28,6 +28,7 @@
import tech.mcprison.prison.spigot.gui.sellall.SellAllAdminBlocksGUI;
import tech.mcprison.prison.spigot.sellall.SellAllBlockData;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
+import tech.mcprison.prison.spigot.utils.tasks.PlayerAutoRankupTask;
/**
* @author GABRYCA
@@ -269,6 +270,9 @@ public void sellAllSellCommand(CommandSender sender,
boolean notifications = (notification != null && "silent".equalsIgnoreCase( notification ));
sellAllUtil.sellAllSell(p, false, notifications, true, true, false, true);
+
+ SpigotPlayer sPlayer = new SpigotPlayer( p );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
}
@Command(identifier = "sellall hand", description = "Sell only what is in your hand if sellable.",
@@ -340,6 +344,11 @@ public void sellAllSell(Player p){
}
sellAllUtil.sellAllSell(p, true, false, true, true, false, true);
+
+
+ SpigotPlayer sPlayer = new SpigotPlayer( p );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
+
}
@Command(identifier = "sellall delaysell", description = "Like SellAll Sell command but this will be delayed for some " +
@@ -380,6 +389,9 @@ public void sellAllSellWithDelayCommand(CommandSender sender){
}
sellAllUtil.sellAllSell(p, false, false, false, false, true, false);
+
+ SpigotPlayer sPlayer = new SpigotPlayer( p );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
index 1bc40011e..afcc99390 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
@@ -77,6 +77,7 @@
import tech.mcprison.prison.spigot.gui.sellall.SellAllPrestigesSetMultiplierGUI;
import tech.mcprison.prison.spigot.gui.sellall.SellAllPriceGUI;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
+import tech.mcprison.prison.spigot.utils.tasks.PlayerAutoRankupTask;
import tech.mcprison.prison.util.Text;
/**
@@ -212,9 +213,17 @@ public void onPlayerInteractEvent(PlayerInteractEvent e){
for (XMaterial xMaterialConf : items) {
if (xMaterialConf == inHandXMaterial) {
sellAllUtil.sellAllSell(p, false, false, true, false, false, true);
+
+ SpigotPlayer sPlayer = new SpigotPlayer( p );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
+
return;
} else if (xMaterialConf == SpigotUtil.getXMaterial(p.getInventory().getItemInMainHand().getType())) {
sellAllUtil.sellAllSell(p, false, false, true, false, false, true);
+
+ SpigotPlayer sPlayer = new SpigotPlayer( p );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, null );
+
return;
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PlayerAutoRankupTask.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PlayerAutoRankupTask.java
new file mode 100644
index 000000000..7f5a60d61
--- /dev/null
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PlayerAutoRankupTask.java
@@ -0,0 +1,62 @@
+package tech.mcprison.prison.spigot.utils.tasks;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import tech.mcprison.prison.Prison;
+import tech.mcprison.prison.ranks.data.PlayerRank;
+import tech.mcprison.prison.ranks.data.RankPlayer;
+import tech.mcprison.prison.spigot.game.SpigotPlayer;
+import tech.mcprison.prison.spigot.utils.tasks.PrisonUtilsTaskTypes.PrisonUtilsTaskTypRunCommand;
+
+public class PlayerAutoRankupTask {
+
+
+ /**
+ *
If the config.yml settings 'prison-mines.forced-auto-rankups' is enabled,
+ * then it will check to see if the player has enough money to rankup.
+ * This will perform all rankups; `/rankup` and `/prestige`. The prestige is
+ * actually just `/rankup prestiges [playerName]`.
+ *
+ *
+ * @param sPlayer
+ */
+ public static void autoSubmitPlayerRankupTask( SpigotPlayer sPlayer, StringBuilder debugInfo ) {
+
+ if ( Prison.get().getPlatform().getConfigBooleanFalse( "prison-mines.forced-auto-rankups" ) ) {
+
+ RankPlayer rPlayer = sPlayer.getRankPlayer();
+
+ PlayerRank nextRank = rPlayer.getNextPlayerRank();
+
+ if ( nextRank != null ) {
+
+ String currency = nextRank.getCurrency();
+ double balance = rPlayer.getBalance( currency );
+
+ double rankBalance = nextRank.getRankCost();
+
+ if ( balance >= rankBalance ) {
+
+ if ( debugInfo != null ) {
+ debugInfo.append( "(forcing auto rankup) " );
+ }
+
+ String cmd =
+ String.format( "rankup %s %s",
+ nextRank.getRank().getLadder().getName(),
+ rPlayer.getName() );
+
+ List tasks = new ArrayList<>();
+ PrisonUtilsTaskTypRunCommand task = new PrisonUtilsTaskTypRunCommand( rPlayer, cmd );
+ tasks.add( task );
+
+ PrisonUtilsTask taskRunner = new PrisonUtilsTask( tasks );
+ taskRunner.submit();
+
+ }
+ }
+
+ }
+ }
+}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PrisonUtilsTaskTypes.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PrisonUtilsTaskTypes.java
index 1c751f5a6..f87217ddf 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PrisonUtilsTaskTypes.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/tasks/PrisonUtilsTaskTypes.java
@@ -144,6 +144,7 @@ public boolean isAsyc() {
return false;
}
+ @SuppressWarnings("unused")
private Player getPlayer() {
return player;
}
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 971b77bb9..75dbaf0fc 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -164,6 +164,7 @@ prison-mines:
enabled: false
movementMaxDistance: 1.0
delayInTicks: 20
+ forced-auto-rankups: false
access-to-prior-mines: true
From 19e58a21355b949cf79eb499955d45b7b8a7b927 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Tue, 30 Aug 2022 00:38:38 -0400
Subject: [PATCH 004/129] New feature: Auto Forced Rankup. When using
autosell, it will auto rankup the player when they have enough money. This
includes both normal /rankup and /prestige. This configuration setting is set
within config.yml in prison-mines.forced-auto-rankups: true.
---
.../prison/spigot/autofeatures/AutoManagerFeatures.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
index 1d0ca15ef..76983c7c1 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
@@ -23,7 +23,6 @@
import com.cryptomorin.xseries.XMaterial;
-import tech.mcprison.prison.Prison;
import tech.mcprison.prison.autofeatures.AutoFeaturesFileConfig.AutoFeatures;
import tech.mcprison.prison.cache.PlayerCache;
import tech.mcprison.prison.internal.block.PrisonBlock;
@@ -41,6 +40,7 @@
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
import tech.mcprison.prison.spigot.spiget.BluesSpigetSemVerComparator;
+import tech.mcprison.prison.spigot.utils.tasks.PlayerAutoRankupTask;
import tech.mcprison.prison.util.Text;
/**
@@ -1064,6 +1064,9 @@ protected void dropExtra( HashMap extra, Player player
}
debugInfo.append( " ] " );
+
+ SpigotPlayer sPlayer = new SpigotPlayer( player );
+ PlayerAutoRankupTask.autoSubmitPlayerRankupTask( sPlayer, debugInfo );
}
}
From 2cda5ea58af15de3c015ec034cf2528a1dd4e03d Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Tue, 30 Aug 2022 17:54:23 -0400
Subject: [PATCH 005/129] Update the mine bombs docs. Major updates.
---
docs/prison_docs_130_Prison_Mine_Bombs.md | 242 +++++++++++++++++++++-
1 file changed, 238 insertions(+), 4 deletions(-)
diff --git a/docs/prison_docs_130_Prison_Mine_Bombs.md b/docs/prison_docs_130_Prison_Mine_Bombs.md
index 53d4d2476..423796a77 100644
--- a/docs/prison_docs_130_Prison_Mine_Bombs.md
+++ b/docs/prison_docs_130_Prison_Mine_Bombs.md
@@ -5,17 +5,24 @@
# Prison Mine Bombs
-Prison mine bombs...
+Prison mine bombs can take on a lot of different sizes, shapes, and strengths.
+
+
+A player can only use a Mine Bomb within a Prison mine, and they cannot activate it outside of a mine.
+
+
+When a Mine Bomb goes off, it identifies a list of blocks that are included in the explosion event, and then it's passed on to prison to process the actual block breaks and apply any special conditions that goes along with those actions.
+
*Note: this document is a work in progress.*
-*Documented updated: 2022-08-06*
+*Documented updated: 2022-08-30*
-Commands:
+# Commands:
```
/prison utils bomb list help
@@ -39,8 +46,235 @@ The location of the configuration file is:
`plugins/Prison/module_conf/mines/mineBombsConfig.json`
-If this file does not exist, you can have prison auto generate it by using any of the above mine bomb commands. The best may be
+If this file does not exist, you can have prison auto generate it by using any of the above mine bomb commands.
+
+
+You can directly edit this file while the server is running, then use `/prison utils bomb reload` to reload it without restarting the server.
+
+
+The format of this config file is JSON, so it very sensitive to typographical errors that breaks the JSON format. If you do mess it up, or if you need to reformat it so it looks pretty, you can use the online JSON lint tool: [JSON Lint Online](https://jsonlint.com/).
+
+
+You can edit almost anything in this config file, except for the field `dataFormatVersion` which is used to identify if the underlying format has changed so prison can use the proper converters to ensure the settings are migrated to future formats. This currently is not being used, but as soon as a major change is made to the data structure, then this will become valuable.
+
+
+
+
+# Config File - Bombs Map
+
+In the config file, "bombs" is the root hash (map, object, key-value-pairs) that contains all bombs. The bombs are keyed on their name, which must be unique.
+
+
+There are no limitations on how many bombs you can create, or have active. You can have 1000's of bombs if you desire.
+
+
+
+
+# Config File - Bomb Structure
+
+The config file for a bomb, contains all of the possible settings that can be used, even if they are not enabled or used. This may make for a verbose bomb listing, but it's part of the process for mapping between JSON and the java data.
+
+
+## Bomb Name and nameTag
+
+Each bomb must have a name, which can include color codes, but the key name for the bomb is the name but minus color codes. It's the key name (without the color codes) becomes the identifier that is used in-game for selecting the bombs. Since bombs are used with commands, the name cannot contain any spaces.
+
+
+Bomb names can include color codes, but it is suggested that the color codes are added to the nameTag. The nameTag can include a limited number of Mine Bomb placeholders to inject various information, such as the bomb name. Placeholders can be used more than once.
+
+
+The list of Mine Bomb nameTag placeholders:
+
+* **{name}** Injects the bomb's name in to the nameTag.
+
+* **{countdown}** Provides a countdown that is refreshed dynamically. This can show the players how long they have before a bomb goes off. The **oofBomb** has an example of this placeholder.'
+
+
+
+
+
+## Bomb itemType
+
+The itemType identifies what the bomb will look like. It can be any item or block as long as the name matches the XSeries' XMaterial types. The itemType must also be valid for your version of Spigot that you're running.
+
+
+You can find a list of XMaterial names here:
+
+[XSeries' XBlock](https://github.com/CryptoMorin/XSeries/blob/master/src/main/java/com/cryptomorin/xseries/XMaterial.java)
+
+
+
+
+ ## Bomb Shapes, Dimensions, and Positions
+
+
+ Most bombs may be round, but they can take on any shape. Prison supports a few different shapes, and the plan is to add more in the near future. To view the current list of shapes use the following command:
+
+`/prison utils bomb list shapes`
+
+
+Explosive Shapes (field **explosionShape**):
+
+* **cube** a cubic bomb that has equal sized dimensions. The length is calculated from the bomb's radius: length = 2r + 1. The **height** may also effect the cube bomb (will have to look it up).
+
+* **sphere** a spherical bomb with a defined **radius**.
+
+* **sphereHollow** a spherical bomb that is defined by it's radius, but the center of the bomb is untouched and its size is defined by the **innerRadius**. The oofBomb is an example of a sphereHollow bomb, where at ground zero it's the safest place to stand.
+
+* **ring_x ring_y ring_z** Creates a hollow ring going through the specified plane. The **radius** defines the size of the ring, and the **innerRadius** defines the size of the hollow inner circle.
+
+* **disk_x disk_y disk_z** Similar to the **ring_** shapes, but instead of hollow, they are filled in.
+
+
+The **radius** is not exactly what someone may think it is. Since we're dealing with Minecraft, we are stuck in block mode, therefore everything must be within whole blocks. So the radius is added to 1, but the total diameter is not 2(r + 1), but instead it is 2r + 1. So given the starting center point, the radius is added to that block. So with a radius == 1, the diameter will be 3. Radius == 5, diameter == 11.
+
+
+The **placementAdjustmentY** is added to the y-axis to move the center of the bomb up when positive, or down when negative. Usually since a bomb is symmetrical, if just placed on the top of a mine, then 1/2 of it would go unused and wasted. So for some bombs it makes sense to adjust the height with a negative value so as to get move coverage. As with any bomb that has decent hight, it would make the most sense to place it in the very center of the mine to maximize the full volume of the explosion.
+
+
+
+
+
+## Removal Chance
+
+
+To weaken an explosion, you can use the field **removalChance** which will randomly check each block to see if it's included in the explosion. Depending upon the percent chance, a few blocks can remain, or all can be removed.
+
+The values range from **100.0** to **0.0001**. At 100.0 percent, all blocks are removed and no chance calculations are performed. At 50.00 percent, then about half will be removed. At very, very low removal chances, it's possible that no blocks will be removed.
+
+
+**Explosive Strength - Future Idea**
+
+Please note that the removal of a block has nothing to do with the hardness of the blocks. In the future, I may add explosive strength to Mine Bombs where the total explosion is calculated in terms of a strength value, then each block, starting at the radius and incorporating a proportatant equation, will determine if the block breaks, and how much of the explosive strength was consumed. This will ensure blocks at ground zero will have more odds of breaking, but blocks on the outer edge will have less of a chance, especially if the explosion runs out of explosive strength. So two identical bombs set off in sand stone (weak blocks) will have a larger blast area than the same bomb set off on obby. For the largest bombs, having such high explosive strength at ground zero, could even include breaking bedrock or even stronger materials.
+
+
+
+
+
+
+## Virtual Tool
+
+When a block is broken, it is taken in to consideration what is hitting the block. Such as the player's hand, a wooden pickaxe, or a diamond pickaxe. But with Mine Bombs, the player is holding the bomb before they set it off, so when breaking the block, it is needed to include a "tool".
+
+This virtual tool is defined with four fields and it actually used to break the blocks. Since some explosions can include tens of thousands, or even millions of blocks (not recommended... lol) the tool never looses durability. Otherwise if it breaks 1/3 of the way while processing the explosion, then 2/3rds of the explosion will remain unbroken.
+
+**toolInHandName** Use XSeries' XMaterial names for this field. See the link above under **Bomb itemType**.
+
+**toolInHandFortuneLevel** sets the fortune level. Uses unsafe enchantments (unlimited). This can greatly impact the amount of the drops.
+
+**toolInHandDurabilityLevel** sets the durability level. Uses unsafe enchantments (unlimited). Since no wear happens, this really is not needed.
+
+**toolInHandDigSpeedLevel** sets the dig speed level. Uses unsafe enchantments (unlimited). Since the block break is instant, this really is not needed.
+
+
+
+
+
+
+## Fuse delay ticks
+
+The fuse delay, in ticks, is the amount of time it takes from placing the bomb to when it goes off.
+
+
+Within the **nameTag** field, you can use the placeholder `{countDown}` to display how much time is remaining. This placeholder can be used multiple times if desired.
+
+
+Valid values are 0 through no limit. But if the server restarts before a bomb goes off, it may orphan the bomb, or actually the armor stand that is used to represent the detonation point. You would have to manually remove these orphaned armor stands with a command.
+
+(to do: provide command to remove the armor stands)
+
+
+
+
+## Cooldown
+
+Once a bomb is used, the field **cooldownTicks** sets how long the player must wait before using that bomb again. A value of 0 has no cooldown.
+
+
+Cooldowns apply to a specific bomb and so if a player has three different kinds in their inventory, they can rapidly set off each one without triggering the cooldowns. So if a player has a stack of 10 smallbombs and it has a cooldown of 10 seconds, then it will take at best, 100 seconds to set them all off.
+
+
+
+
+## Item Removal Delay Ticks
+
+Just because the bomb goes off, does not mean the item that represents the bomb is removed. It must be manually removed from the game or it will just fall and sit at the bottom of the mine, and no one will be able to pick it up.
+
+
+The field **itemRemovalDelayTicks** is the number of ticks that prison waits after setting off the bomb, before it removes the item from the game. This is important, since if it is removed as soon as the bomb goes off, the player may see it disappear before the explosion and block removal happens. But setting to a small value of ticks, the item can become lost in the visual effects so when it's removed, it's not noticeable.
+
+
+
+## Glowing
+
+Glowing does not work well on all versions of spigot. Some versions it's horrible and the whole armor stand glows, other versions does not glow at all. But if you are using a version of spigot where it only glows the itemType, then it's a cool effect. Glowing will allow you, and other players, to see it through other objects and blocks. Kind of like a massive warning of doom.
+
+Because it may not always work as expected, please test on your server and confirm if it's what like. If not, then disable the field **glowing** by setting to a value of false.
+
+
+
+
+## Gravity
+
+Just like glowing, the effects may not be what you want. The idea was to place a bomb somewhere, even within the air, and have it ignore gravitational effects. Kind of like hovering, or like Wile e Coyote the moment before he realizes he's ran off the edge of a cliff and is about to fall.
+
+The reality is that in my testing, the mine bomb items just kind of float off in to space and it's totally a dud. But hey, it's a feature, so maybe you can find a cool way to use them, such as drifting mines that go off in 5 minutes (oh the waiting! lol) so you have no idea where it will wind up within a cavernous mine.
+
+
+
+
+
+## Autosell
+
+With super-large bombs that can produce many times the drops than what a player has the capacity to hold in their inventory, **autosell** will automatically sell every item that was included in that explosive drop. Even if auto feature's autosell is turned off, this will override that setting and sell it for the players.
+
+As a warning, if you have a super-large explosion, and it drops the blocks, the density of the block pile can overload the player's inventory to the point that it can cause glitching. It can also potentially cause lag too if the entity counts become too high. On my test server, with the oof bomb dropping overflows, it can be almost impossible to pickup all of the blocks, or you have to go in to inventory and move a stack of blocks to get them to popuplate within the player's inventory. So autosell on super huge explosions can eliminate all this mess.
+
+
+
+
+## Sound and Visual Effects - Disclaimer
+
+Prison supports Spigot 1.8.8 through 1.19.x. Over the years, and with many different versions of minecraft, the names for sound and visual effects have changed. Because prison "tries" to support a wide range of versions, the demo mine bombs includes a variety of sound effects and visual effects for the wide range of versions just so something works. Therefore, it is perfectly normal for the demo mine bombs to show warnings that a particular effect does not exist. Just ignore them, or better yet, remove the ones that are not compatible for your version of spigot.
+
+Newer versions of spigot has a lot more sound and visual effects than older versions. Way more!
+
+To list what works on your server, run the following commands in the console. If you're using spigot 1.19.x, then this list will be huge and you will have to do a lot of scrolling.
+
+
+```
+/prison utils bomb list help
+
+/prison utils bomb list sounds
+/prison utils bomb list visuals
+```
+
+Also, internally, Prison is using the same data object to hold both the sound effects and the visual effects. Therefore the visual effects in the save file lists **volume** and **pitch**. You can ignore them and just use the default value of 1.0 for those fields.
+
+
+
+## Sound and Visual Effects
+
+The sound and visual effects are played at different points within the explosion event. These points are identified with **effectState** and the values are:
+
+* **placed** The starting point is when the bomb is place. An **offsetTicks** of zero runs the effect instantly. Positive values are ticks after placement with no restrictions on max value, but should be within reason.
+
+* **explode** The starting point for this state is when the bomb explodes. An **offsetTicks** of zero runs the effects when the bomb "explodes". A negative value will run the effect before the explosion. A position value will run the effect after the explosion.
+
+
+* **finished** The starting point for this state is when everything is done. I'm not sure about the **offsetTicks** since finished should be done.
+
+
+
+**volumne**: Yeah, there's a typo in there... lol
+
+Default volume is 1.0. Less is quieter and higher is louder.
+
+
+**pitch** Changes the pitch. 1.0 is the default. Less is lower, and higher is a much higher pitch.
+
+
From c77dd08b469f0a15f8f4cdb48efe3a648c76570e Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 31 Aug 2022 13:26:30 -0400
Subject: [PATCH 006/129] Add to the platform the ability to get a specific
RankLadder.
---
docs/changelog_v3.3.x.md | 5 ++++-
.../tech/mcprison/prison/internal/platform/Platform.java | 4 ++++
.../src/test/java/tech/mcprison/prison/TestPlatform.java | 6 ++++++
.../java/tech/mcprison/prison/spigot/SpigotPlatform.java | 8 ++++++++
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 0627202b9..78d7f13b7 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13 2022-08-29
+# 3.3.0-alpha.13 2022-08-31
+
+
+* **Add to the platform the ability to get a specific RankLadder.**
* **New feature: Auto Forced Rankup. When using autosell, it will auto rankup the player when they have enough money.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java b/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
index ef04889de..f16459a04 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/internal/platform/Platform.java
@@ -40,6 +40,7 @@
import tech.mcprison.prison.modules.ModuleElementType;
import tech.mcprison.prison.output.ChatDisplay;
import tech.mcprison.prison.placeholders.Placeholders;
+import tech.mcprison.prison.ranks.data.RankLadder;
import tech.mcprison.prison.ranks.data.RankPlayer;
import tech.mcprison.prison.store.Storage;
import tech.mcprison.prison.util.Location;
@@ -446,5 +447,8 @@ public void autoCreateMineLinerAssignment( List rankMineNames,
public void sellall(RankPlayer rankPlayer);
+
+
+ public RankLadder getRankLadder( String ladderName );
}
diff --git a/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java b/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
index 92bcd6c7f..c3d8a5bc2 100644
--- a/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
+++ b/prison-core/src/test/java/tech/mcprison/prison/TestPlatform.java
@@ -48,6 +48,7 @@
import tech.mcprison.prison.modules.ModuleElementType;
import tech.mcprison.prison.output.ChatDisplay;
import tech.mcprison.prison.placeholders.PlaceholderManager.PlaceholderFlags;
+import tech.mcprison.prison.ranks.data.RankLadder;
import tech.mcprison.prison.ranks.data.RankPlayer;
import tech.mcprison.prison.placeholders.Placeholders;
import tech.mcprison.prison.store.Storage;
@@ -511,4 +512,9 @@ public void listAllMines(CommandSender sender, Player player) {
public void sellall( RankPlayer rankPlayer ) {
}
+
+ @Override
+ public RankLadder getRankLadder(String ladderName) {
+ return null;
+ }
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index 3bb6503f9..ef35e8b71 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -2937,4 +2937,12 @@ public void sellall( RankPlayer rankPlayer ) {
}
}
}
+
+
+ @Override
+ public RankLadder getRankLadder(String ladderName) {
+
+ RankLadder results = PrisonRanks.getInstance().getLadderManager().getLadder( ladderName );
+ return results;
+ }
}
From 352f512e7956cbcbb604279f348784e95ae8fe62 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 31 Aug 2022 13:40:15 -0400
Subject: [PATCH 007/129] Fixed an issue with the
RankPlayer.getNextPlayerRank() which was not returning the first prestige
rank if at end of default and no prestiges. Had to hook in to the
LadderManager, routing through Platform, to get the presetiges ladder to pull
the first prestige rank. Adding this capability expands the functional
usefulness of this function greatly. Now if this function returns a null,
then it means the player is at the last possible rank.
---
docs/changelog_v3.3.x.md | 5 +++++
.../prison/ranks/data/RankPlayer.java | 20 ++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 78d7f13b7..010c3a8a9 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -15,6 +15,11 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13 2022-08-31
+* **Fixed an issue with the RankPlayer.getNextPlayerRank() which was not returning the first prestige rank if at end of default and no prestiges.**
+Had to hook in to the LadderManager, routing through Platform, to get the presetiges ladder to pull the first prestige rank.
+Adding this capability expands the functional usefulness of this function greatly. Now if this function returns a null, then it means the player is at the last possible rank.
+
+
* **Add to the platform the ability to get a specific RankLadder.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
index 569cfc680..507f0e2ef 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
@@ -1429,6 +1429,19 @@ public boolean isSneaking() {
return false;
}
+
+ /**
+ *
This function will return the next rank that they player will have upon
+ * rankup. This includes going from the end of the default ladder to the next
+ * rank on prestiges ladder.
+ *
+ *
+ *
If this function return a null value, then the player has reached the
+ * end of the game, and they are at the top-most rank.
+ *
The plugin is shutting down so flush all dirty cache items, but first
+ * disable the caching so as any changes are passed through directly to the
+ * database.
+ *
+ *
+ *
Since the plugin is shutting down, flush the cache synchronously in this
+ * thread. Do not submit, or the database may be shutdown before all dirty
+ * cache items can be saved.
+ *
This shuts down the cache and unloads all the players while
+ * updating the database if they have uncommitted values. This also
+ * will cancel any outstanding tasks and then flush the uncommitted
+ * values if they still exist.
+ *
+ *
+ *
This function runs all database transactions synchronously so as to
+ * ensure all data is written to the database before the server is
+ * terminated.
+ *
+ *
+ */
+ private void onDisableInternal() {
+
+ // Shutdown the save all task so it won't reload players or try to refresh data:
+ PrisonTaskSubmitter.cancelTask( saveAllTask.getTaskId() );
+
+ // Shutdown the timerTasks
+// PrisonTaskSubmitter.cancelTask( checkTimersTask.getTaskId() );
+
+
+ // save all dirty cache items and purge cache:
+ if ( getPlayers().size() > 0 ) {
+
+
+ Set keys = getPlayers().keySet();
+
+ synchronized ( getPlayers() ) {
+
+ for ( String key : keys ) {
+ // Remove the player from the cache and get the playerData:
+ BackpackCachePlayerData playerData = getPlayers().remove( key );
+
+ if ( playerData != null ) {
+
+ // Note: Since we are logging online time, then all players that are
+ // in the cache are considered constantly dirty and needs to be
+ // saved.
+
+ // Since the disable function has been called, we can only assume the
+ // server is shutting down. We need to save dirty player caches, but
+ // they must be done in-line so the shutdown process will wait for all
+ // players to be saved.
+
+ getCacheFiles().toJsonFile( playerData );
+
+ if ( playerData.getTask() != null ) {
+
+ synchronized( getTasks() ) {
+
+ getTasks().remove( playerData.getTask() );
+ }
+
+ PrisonTaskSubmitter.cancelTask( playerData.getTask().getTaskId() );
+ }
+ }
+ }
+ }
+
+ }
+
+ // Cancel and flush any uncompleted tasks that are scheduled to run:
+ if ( getTasks().size() > 0 ) {
+
+
+ Set keys = getTasks().keySet();
+
+ for ( BackpackCacheRunnable key : keys ) {
+
+ if ( !key.isCancelled() ) {
+ // Cancel the task:
+ key.cancel();
+
+ // Remove the task and get the player data:
+ BackpackCachePlayerData playerData = null;
+
+ synchronized( getTasks() ) {
+
+ playerData = getTasks().remove( key );
+ }
+
+ if ( playerData != null &&
+ playerData.getTask() != null &&
+ playerData.getTask().getTaskId() > 0 ) {
+
+ PrisonTaskSubmitter.cancelTask( playerData.getTask().getTaskId() );
+ }
+
+ }
+ }
+
+ }
+
+ // Shutdown the connections:
+
+ }
+
+
+
+ public void addPlayerData( BackpackCachePlayerData playerData ) {
+
+ if ( playerData != null ) {
+ getStats().incrementLoadPlayers();
+
+ synchronized ( getPlayers() ) {
+
+ getPlayers().put( playerData.getPlayerUuid(), playerData );
+ }
+
+ }
+ }
+
+ public BackpackCachePlayerData removePlayerData( BackpackCachePlayerData playerData ) {
+ BackpackCachePlayerData removed = playerData;
+ if ( playerData != null ) {
+ getStats().incrementRemovePlayers();
+
+ synchronized ( getPlayers() ) {
+
+ removed = getPlayers().remove( playerData.getPlayerUuid() );
+ }
+ }
+ return removed;
+ }
+
+
+ /**
+ *
This function will return a null if the player is not loaded in the cache.
+ * Null is a valid value even if the player is online.
+ * This function should NEVER be used
+ * for any critical data such as tracking blocks, time, earnings, or inventory.
+ * Examples of acceptable loss would be with messaging. Loss of a few messages is
+ * not that critical, and actually would be a very rare situation. Example, if a
+ * player is mining then their cache should already be loaded so calling this function
+ * should never find the situation where the player's cache entry does not exist.
+ *
+ *
+ *
Since this function will fail with the return a null if the player is not loaded,
+ * this function will not cause blocking on the runnable thread.
+ *
+ *
+ *
If the player is not loaded, and a null is returned, then an async task
+ * will be submitted to load it.
+ *
+ *
+ * @param player
+ * @return
+ */
+ public BackpackCachePlayerData getOnlinePlayer( Player player ) {
+ BackpackCachePlayerData playerData = getPlayer( player );
+
+ return playerData;
+ }
+
+ private BackpackCachePlayerData getPlayer( Player player ) {
+ return getPlayer( player, true );
+ }
+
+
+ /**
+ *
This returns the cached player object. If they have not been loaded
+ * yet, then this will load the player object while waiting for it.
+ *
+ *
+ *
This used to return a null while submitting a loadPlayer task.
+ *
+ *
+ * @param player
+ * @return The cached player object. If null, then may indicate the player is
+ * actively being loaded, so try again later.
+ */
+ private BackpackCachePlayerData getPlayer( Player player, boolean loadIfNotInCache ) {
+ BackpackCachePlayerData playerData = null;
+ getStats().incrementGetPlayers();
+
+ if ( player != null && player.getUUID() != null ) {
+
+ String playerUuid = player.getUUID().toString();
+
+
+ if ( getPlayers().containsKey( playerUuid ) ) {
+
+ // Note: if the player has not been loaded yet, this will return a null:
+ synchronized ( getPlayers() ) {
+
+ playerData = getPlayers().get( playerUuid );
+ }
+ }
+ else if ( loadIfNotInCache ) {
+
+ // Load the player's existing balance:
+ playerData = getCacheFiles().fromJson( player );
+
+ // NOTE: playerData.isOnline() is dynamic and tied back to the Player object.
+ // So if they are offline, an OfflinePlayer, then it will automatically
+ // track that. Also if the PlayerData object does not have a reference
+ /// to Player, then it's automatically considered offline.
+
+ // Save it to the cache:
+ addPlayerData( playerData );
+// runLoadPlayerNow( player );
+// submitAsyncLoadPlayer( player );
+ }
+
+ if ( playerData != null ) {
+
+ if ( playerData.getPlayer() == null || !playerData.getPlayer().equals( player ) ) {
+
+ playerData.setPlayer( player );
+ }
+
+// playerData.updateLastSeen();
+ }
+ }
+
+ return playerData;
+ }
+
+
+ protected void submitAsyncLoadPlayer( Player player ) {
+
+ if ( player != null ) {
+
+ BackpackCacheLoadPlayerTask task = new BackpackCacheLoadPlayerTask( player );
+
+ // Submit task to run right away:
+ int taskId = PrisonTaskSubmitter.runTaskLaterAsync( task, 0 );
+ task.setTaskId( taskId );
+ }
+ }
+
+
+// /**
+// *
This loads the player cache object inline. It does not run it as a
+// * task in another thread.
+// *
+// *
+// *
This is not used anywhere.
+// *
+// *
+// * @param player
+// */
+// protected void runLoadPlayerNow( Player player ) {
+//
+// if ( player != null ) {
+//
+// PlayerCacheLoadPlayerTask task = new PlayerCacheLoadPlayerTask( player );
+//
+// task.run();
+//// // Submit task to run right away:
+//// int taskId = PrisonTaskSubmitter.runTaskLaterAsync( task, 0 );
+//// task.setTaskId( taskId );
+// }
+// }
+
+
+ protected void submitAsyncUnloadPlayer( Player player ) {
+
+ BackpackCachePlayerData playerData = getPlayer( player, false );
+
+ if ( playerData != null ) {
+
+ // Submit to unload right away with no delay:
+ BackpackCacheUnloadPlayerTask task = new BackpackCacheUnloadPlayerTask( playerData );
+ int taskId = PrisonTaskSubmitter.runTaskLaterAsync( task, 0 );
+ task.setTaskId( taskId );
+ }
+ }
+
+
+
+ /**
+ * Submit task to run only once. Should be started when this cache initializes.
+ *
+ */
+ public BackpackCacheRunnable submitCacheRefresh() {
+
+ BackpackCacheSaveAllPlayersTask task = new BackpackCacheSaveAllPlayersTask();
+
+ // Submit Timer Task to start running in 10 minutes (6000 ticks) and then
+ // refresh stats every 5 minutes (3000 ticks):
+ int taskId = PrisonTaskSubmitter.runTaskTimerAsync( task, 6000, 3000 );
+ task.setTaskId( taskId );
+
+ return task;
+ }
+
+
+
+ public BackpackCacheFiles getCacheFiles() {
+ return cacheFiles;
+ }
+ public void setCacheFiles(BackpackCacheFiles cacheFiles) {
+ this.cacheFiles = cacheFiles;
+ }
+
+ public BackpackCacheEvents getCacheEvents() {
+ return cacheEvents;
+ }
+ public void setCacheEvents(BackpackCacheEvents cacheEvents) {
+ this.cacheEvents = cacheEvents;
+ }
+
+ public PlayerCacheStats getStats() {
+ return stats;
+ }
+ public void setStats(PlayerCacheStats stats) {
+ this.stats = stats;
+ }
+
+ public SortedMap getPlayers() {
+ return players;
+ }
+ public void setPlayers(SortedMap players) {
+ this.players = players;
+ }
+
+ public Map getTasks() {
+ return tasks;
+ }
+ public void setTasks(Map tasks) {
+ this.tasks = tasks;
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheEvents.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheEvents.java
new file mode 100644
index 000000000..2b4e3a1c7
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheEvents.java
@@ -0,0 +1,40 @@
+package tech.mcprison.prison.backpacks;
+
+import com.google.common.eventbus.Subscribe;
+
+import tech.mcprison.prison.Prison;
+import tech.mcprison.prison.internal.Player;
+import tech.mcprison.prison.internal.events.player.PlayerJoinEvent;
+import tech.mcprison.prison.internal.events.player.PlayerKickEvent;
+import tech.mcprison.prison.internal.events.player.PlayerQuitEvent;
+
+public class BackpackCacheEvents {
+
+ public BackpackCacheEvents() {
+ super();
+
+ Prison.get().getEventBus().register(this);
+ }
+
+
+ @Subscribe
+ public void onPlayerJoin(PlayerJoinEvent event) {
+
+ Player player = event.getPlayer();
+ BackpackCache.getInstance().submitAsyncLoadPlayer( player );
+ }
+
+ @Subscribe
+ public void onPlayerQuit(PlayerQuitEvent event) {
+
+ Player player = event.getPlayer();
+ BackpackCache.getInstance().submitAsyncUnloadPlayer( player );
+ }
+
+ @Subscribe
+ public void onPlayerKicked(PlayerKickEvent event) {
+
+ Player player = event.getPlayer();
+ BackpackCache.getInstance().submitAsyncUnloadPlayer( player );
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheFiles.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheFiles.java
new file mode 100644
index 000000000..0109b0ddb
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheFiles.java
@@ -0,0 +1,25 @@
+package tech.mcprison.prison.backpacks;
+
+import tech.mcprison.prison.cache.CoreCacheData;
+import tech.mcprison.prison.cache.CoreCacheFiles;
+import tech.mcprison.prison.internal.Player;
+
+public class BackpackCacheFiles
+ extends CoreCacheFiles
+{
+ public static final String FILE_BACKPACK_CACHE_PATH = "data_storage/backpackCache";
+
+
+ public BackpackCacheFiles() {
+ super( FILE_BACKPACK_CACHE_PATH );
+
+ }
+
+ public BackpackCachePlayerData fromJson( Player player ) {
+
+ CoreCacheData results = fromJson( player, BackpackCachePlayerData.class );
+
+ return (BackpackCachePlayerData) results;
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheLoadPlayerTask.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheLoadPlayerTask.java
new file mode 100644
index 000000000..7d1de58a2
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheLoadPlayerTask.java
@@ -0,0 +1,32 @@
+package tech.mcprison.prison.backpacks;
+
+import tech.mcprison.prison.internal.Player;
+
+public class BackpackCacheLoadPlayerTask
+ extends BackpackCacheTask
+{
+
+ private Player player;
+
+ public BackpackCacheLoadPlayerTask( Player player ) {
+ super( null );
+
+ this.player = player;
+ }
+
+ public void run() {
+
+ BackpackCache bCache = BackpackCache.getInstance();
+
+ BackpackCachePlayerData playerData = bCache.getCacheFiles().fromJson( player );
+
+ if ( playerData != null ) {
+
+ synchronized ( bCache.getPlayers() ) {
+
+ }
+ }
+
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCachePlayerData.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCachePlayerData.java
new file mode 100644
index 000000000..5125a8b4f
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCachePlayerData.java
@@ -0,0 +1,103 @@
+package tech.mcprison.prison.backpacks;
+
+import java.io.File;
+import java.util.TreeMap;
+
+import tech.mcprison.prison.cache.CoreCacheData;
+import tech.mcprison.prison.internal.Player;
+
+public class BackpackCachePlayerData
+ implements CoreCacheData {
+
+ private transient Player player;
+
+ private String playerUuid;
+ private String playerName;
+
+ private transient File playerFile = null;
+
+// /**
+// * This Object lock is used to synchronized the public side of this class
+// * and the protected side of this class which is the database transaction
+// * side of things.
+// */
+// @SuppressWarnings( "unused" )
+// private transient final Object lock = new Object();
+
+ private transient BackpackCacheRunnable task = null;
+
+
+ private TreeMap backpacks;
+
+
+ private transient boolean dirty = false;
+
+
+ public BackpackCachePlayerData() {
+ super();
+
+ this.backpacks = new TreeMap<>();
+ }
+
+ public BackpackCachePlayerData( Player player, File playerFile ) {
+ this();
+
+ this.player = player;
+
+
+ this.playerUuid = player.getUUID().toString();
+ this.playerName = player.getName();
+
+ this.playerFile = playerFile;
+
+ }
+
+ protected Player getPlayer() {
+ return player;
+ }
+ protected void setPlayer( Player player ) {
+ this.player = player;
+ }
+
+ public TreeMap getBackpacks() {
+ return backpacks;
+ }
+ public void setBackpacks(TreeMap backpacks) {
+ this.backpacks = backpacks;
+ }
+
+ public File getPlayerFile() {
+ return playerFile;
+ }
+ public void setPlayerFile( File playerFile ) {
+ this.playerFile = playerFile;
+ }
+
+ public String getPlayerUuid() {
+ return playerUuid;
+ }
+ public void setPlayerUuid( String playerUuid ) {
+ this.playerUuid = playerUuid;
+ }
+
+ public String getPlayerName() {
+ return playerName;
+ }
+ public void setPlayerName( String playerName ) {
+ this.playerName = playerName;
+ }
+
+ public BackpackCacheRunnable getTask() {
+ return task;
+ }
+ public void setTask(BackpackCacheRunnable task) {
+ this.task = task;
+ }
+
+ public boolean isDirty() {
+ return dirty;
+ }
+ public void setDirty( boolean dirty ) {
+ this.dirty = dirty;
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheRunnable.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheRunnable.java
new file mode 100644
index 000000000..cd55ca89d
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheRunnable.java
@@ -0,0 +1,32 @@
+package tech.mcprison.prison.backpacks;
+
+import tech.mcprison.prison.tasks.PrisonRunnable;
+
+public abstract class BackpackCacheRunnable
+ implements PrisonRunnable {
+
+ private int taskId = 0;
+ private boolean cancelled = false;
+
+ public BackpackCacheRunnable() {
+ super();
+
+ }
+
+ public int getTaskId() {
+ return taskId;
+ }
+ public void setTaskId( int taskId ) {
+ this.taskId = taskId;
+ }
+
+ public void cancel() {
+ setCancelled( true );
+ }
+ public boolean isCancelled() {
+ return cancelled;
+ }
+ public void setCancelled( boolean cancelled ) {
+ this.cancelled = cancelled;
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheSaveAllPlayersTask.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheSaveAllPlayersTask.java
new file mode 100644
index 000000000..6d2ba01be
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheSaveAllPlayersTask.java
@@ -0,0 +1,91 @@
+package tech.mcprison.prison.backpacks;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import tech.mcprison.prison.Prison;
+import tech.mcprison.prison.internal.Player;
+import tech.mcprison.prison.output.Output;
+
+public class BackpackCacheSaveAllPlayersTask
+ extends BackpackCacheRunnable
+{
+ public static long LAST_SEEN_INTERVAL_30_MINUTES = 30 * 60 * 1000;
+
+ @Override
+ public void run()
+ {
+
+ BackpackCache bCache = BackpackCache.getInstance();
+
+
+ List onlinePlayersList = Prison.get().getPlatform().getOnlinePlayers();
+ Set onlinePlayers = new HashSet<>();
+ for ( Player player : onlinePlayersList ) {
+ onlinePlayers.add( player.getUUID().toString() );
+ }
+
+
+ List purge = new ArrayList<>();
+
+ Set keys = bCache.getPlayers().keySet();
+
+ for ( String key : keys )
+ {
+ BackpackCachePlayerData playerData = null;
+
+ synchronized ( bCache.getPlayers() ) {
+
+ playerData = bCache.getPlayers().get( key );
+ }
+
+ if ( playerData != null ) {
+
+ // If a cached item is found with the player being offline, then
+ // purge them from the cache. They were usually added only because
+ // some process had to inspect their stats, so they are safe to remove.
+ String uuid = playerData.getPlayerUuid();
+ if ( uuid != null && !onlinePlayers.contains( uuid ) ) {
+ purge.add( playerData );
+ }
+
+ if ( playerData.isDirty() ) {
+
+ try
+ {
+ playerData.setDirty( false );
+ bCache.getCacheFiles().toJsonFile( playerData );
+ }
+ catch ( Exception e )
+ {
+ String message = String.format(
+ "PlayerCache: Error trying to save a player's " +
+ "cache data. Will try again later. " +
+ "%s", e.getMessage() );
+ Output.get().logError( message, e );
+ }
+ }
+ }
+
+ }
+
+ synchronized ( bCache.getPlayers() ) {
+
+ for ( BackpackCachePlayerData playerData : purge ) {
+ try {
+ if ( !playerData.isDirty() ) {
+
+ bCache.getPlayers().remove( playerData.getPlayerUuid() );
+ }
+ }
+ catch ( Exception e ) {
+ // Ignore any possible errors. They will be addressed on the next
+ // run of this task.
+ }
+ }
+ }
+
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheStats.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheStats.java
new file mode 100644
index 000000000..d6ca4d846
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheStats.java
@@ -0,0 +1,161 @@
+package tech.mcprison.prison.backpacks;
+
+public class BackpackCacheStats {
+
+ private long startMs;
+
+ private boolean enabled = false;
+
+ private int loadBackpack = 0;
+ private int unloadBackpack = 0;
+ private int removeBackpack = 0;
+ private int getBackpack = 0;
+
+ private int submitDatabaseUpdate = 0;
+ private int synchronizeBackpacks = 0;
+
+
+ private Object lock1 = new Object();
+ private Object lock2 = new Object();
+ private Object lock3 = new Object();
+ private Object lock4 = new Object();
+ private Object lock5 = new Object();
+ private Object lock6 = new Object();
+
+ public BackpackCacheStats() {
+ super();
+
+ this.startMs = System.currentTimeMillis();
+ }
+
+
+ /**
+ *
If enabled, stats will be collected.
+ *
+ *
+ * @return
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+ public void setEnabled( boolean enabled ) {
+ this.enabled = enabled;
+ }
+ public void toggleEnabled() {
+ this.enabled = !this.enabled;
+ }
+
+ public String displayStats() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "BackpackCache stats: loadPlayer=" ).append( getLoadBackpack() )
+ .append( " unloadPlayer=" ).append( getUnloadBackpack() )
+ .append( " removePlayer=" ).append( getRemoveBackpack() )
+ .append( " getPlayer=" ).append( getGetBackpack() )
+
+ .append( " submitDatabaseUpdate=" ).append( getSubmitDatabaseUpdate() )
+ .append( " synchronizeDatabase=" ).append( getSynchronizeBackpacks() )
+
+ ;
+
+ return sb.toString();
+ }
+
+
+ public void incrementGetBackpacks() {
+ if ( enabled ) {
+ synchronized ( lock1 ) {
+ getBackpack++;
+ }
+ }
+ }
+ public void incrementRemoveBackpacks() {
+ if ( enabled ) {
+ synchronized ( lock2 ) {
+ removeBackpack++;
+ }
+ }
+ }
+ public void incrementLoadBackpacks() {
+ if ( enabled ) {
+ synchronized ( lock3 ) {
+ loadBackpack++;
+ }
+ }
+ }
+ public void incrementUnloadBackpacks() {
+ if ( enabled ) {
+ synchronized ( lock4 ) {
+ unloadBackpack++;
+ }
+ }
+ }
+
+
+ public void incrementSubmitDatabaseUpdate() {
+ if ( enabled ) {
+ synchronized ( lock5 ) {
+ submitDatabaseUpdate++;
+ }
+ }
+ }
+ public void incrementSubmitSynchronizeBackpacks() {
+ if ( enabled ) {
+ synchronized ( lock6 ) {
+ synchronizeBackpacks++;
+ }
+ }
+ }
+
+
+
+ public long getStartMs() {
+ return startMs;
+ }
+ public void setStartMs(long startMs) {
+ this.startMs = startMs;
+ }
+
+ public int getLoadBackpack() {
+ return loadBackpack;
+ }
+ public void setLoadBackpack(int loadBackpack) {
+ this.loadBackpack = loadBackpack;
+ }
+
+ public int getUnloadBackpack() {
+ return unloadBackpack;
+ }
+ public void setUnloadBackpack(int unloadBackpack) {
+ this.unloadBackpack = unloadBackpack;
+ }
+
+ public int getRemoveBackpack() {
+ return removeBackpack;
+ }
+ public void setRemoveBackpack(int removeBackpack) {
+ this.removeBackpack = removeBackpack;
+ }
+
+ public int getGetBackpack() {
+ return getBackpack;
+ }
+ public void setGetBackpack(int getBackpack) {
+ this.getBackpack = getBackpack;
+ }
+
+ public int getSubmitDatabaseUpdate() {
+ return submitDatabaseUpdate;
+ }
+ public void setSubmitDatabaseUpdate(int submitDatabaseUpdate) {
+ this.submitDatabaseUpdate = submitDatabaseUpdate;
+ }
+
+ public int getSynchronizeBackpacks() {
+ return synchronizeBackpacks;
+ }
+ public void setSynchronizeBackpack(int synchronizeBackpacks) {
+ this.synchronizeBackpacks = synchronizeBackpacks;
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheTask.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheTask.java
new file mode 100644
index 000000000..4c645d75d
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheTask.java
@@ -0,0 +1,19 @@
+package tech.mcprison.prison.backpacks;
+
+import tech.mcprison.prison.cache.PlayerCacheRunnable;
+
+public abstract class BackpackCacheTask
+ extends PlayerCacheRunnable
+{
+ private final BackpackCachePlayerData backpackData;
+
+ public BackpackCacheTask( BackpackCachePlayerData backpackData ) {
+ super();
+
+ this.backpackData = backpackData;
+ }
+
+ public BackpackCachePlayerData getBackpackData() {
+ return backpackData;
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheUnloadPlayerTask.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheUnloadPlayerTask.java
new file mode 100644
index 000000000..d97829ff7
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackCacheUnloadPlayerTask.java
@@ -0,0 +1,30 @@
+package tech.mcprison.prison.backpacks;
+
+public class BackpackCacheUnloadPlayerTask
+ extends BackpackCacheTask
+{
+
+ public BackpackCacheUnloadPlayerTask( BackpackCachePlayerData backpackData ) {
+ super( backpackData );
+
+ }
+
+ public void run() {
+
+ BackpackCache bCache = BackpackCache.getInstance();
+
+ // Remove from the player cache:
+ BackpackCachePlayerData removed = null;
+
+ synchronized ( bCache.getPlayers() ) {
+
+ removed = bCache.removePlayerData( getBackpackData() );
+ }
+
+ if ( removed != null ) {
+
+ bCache.getCacheFiles().toJsonFile( removed );
+ }
+
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java
new file mode 100644
index 000000000..c193f3766
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java
@@ -0,0 +1,23 @@
+package tech.mcprison.prison.backpacks;
+
+public class BackpackEnums {
+
+ public enum BackpackType {
+ inventory, // Uses standard inventory object, up to 6 rows, 9 stacks each
+ silo; // Up to 54 silos per backpack, which will use a chest to display
+ }
+
+ public enum BackpackFeatures {
+ soulboundBackpack, // If player dies, they keep the backpack
+ soulboundItems, // if soulboundBackpack is enabled, this will preserve items within
+ virtual, // if not virtual, then the itemType must exist in their inventory
+ tradable, // Able to trade/sell whole backpack with contents
+ droppable, // able to remove the backpack item from inventory
+ enablePickup, // normally picked up items go in to backpack
+ enableSellall, // sellall will sell from backpack
+ enablePlayerToggle, // player pickup toggleable
+ enableSellallToggle, // player sellall toggleable
+ enchanted, // show enchant glow on item
+ placeable; // Able to place backpack as a chest - may need to supply empty chests
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpack.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpack.java
new file mode 100644
index 000000000..992b07fa7
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpack.java
@@ -0,0 +1,138 @@
+package tech.mcprison.prison.backpacks;
+
+import java.util.Set;
+import java.util.TreeMap;
+
+import tech.mcprison.prison.backpacks.BackpackEnums.BackpackFeatures;
+import tech.mcprison.prison.backpacks.BackpackEnums.BackpackType;
+import tech.mcprison.prison.internal.inventory.PlayerInventory;
+
+public class PlayerBackpack {
+
+ private String playerName;
+ private String playerUuid;
+
+ private String name;
+ private String itemType; // XMaterial
+
+ private Set features;
+
+ // either inventory or silos... not both... not neither:
+ private BackpackType backpackType;
+
+ private PlayerInventory inventory;
+ private int inventorySize;
+
+
+ // if max of 54 silos, then can use a double-chest to view as GUI and
+ // show the itemStacks with quantity being added lore?
+ private TreeMap silos;
+ private int maxSiloSlots;
+ private int maxSiloSize;
+ private int maxTotalSize; // all silos combined
+
+ public PlayerBackpack() {
+ super();
+
+ this.silos = new TreeMap<>();
+
+ }
+
+ public PlayerBackpack( String playerName, String playerUuid,
+ BackpackType backpackType,
+ String backpackName, String itemType ) {
+ this();
+
+ this.playerName = playerName;
+ this.playerUuid = playerUuid;
+
+ this.backpackType = backpackType;
+ this.name = backpackName;
+ this.itemType = itemType;
+ }
+
+ public String getPlayerName() {
+ return playerName;
+ }
+ public void setPlayerName(String playerName) {
+ this.playerName = playerName;
+ }
+
+ public String getPlayerUuid() {
+ return playerUuid;
+ }
+ public void setPlayerUuid(String playerUuid) {
+ this.playerUuid = playerUuid;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getItemType() {
+ return itemType;
+ }
+ public void setItemType(String itemType) {
+ this.itemType = itemType;
+ }
+
+ public Set getFeatures() {
+ return features;
+ }
+ public void setFeatures(Set features) {
+ this.features = features;
+ }
+
+ public BackpackType getBackpackType() {
+ return backpackType;
+ }
+ public void setBackpackType(BackpackType backpackType) {
+ this.backpackType = backpackType;
+ }
+
+ public PlayerInventory getInventory() {
+ return inventory;
+ }
+ public void setInventory(PlayerInventory inventory) {
+ this.inventory = inventory;
+ }
+
+ public int getInventorySize() {
+ return inventorySize;
+ }
+ public void setInventorySize(int inventorySize) {
+ this.inventorySize = inventorySize;
+ }
+
+ public TreeMap getSilos() {
+ return silos;
+ }
+ public void setSilos(TreeMap silos) {
+ this.silos = silos;
+ }
+
+ public int getMaxSiloSlots() {
+ return maxSiloSlots;
+ }
+ public void setMaxSiloSlots(int maxSiloSlots) {
+ this.maxSiloSlots = maxSiloSlots;
+ }
+
+ public int getMaxSiloSize() {
+ return maxSiloSize;
+ }
+ public void setMaxSiloSize(int maxSiloSize) {
+ this.maxSiloSize = maxSiloSize;
+ }
+
+ public int getMaxTotalSize() {
+ return maxTotalSize;
+ }
+ public void setMaxTotalSize(int maxTotalSize) {
+ this.maxTotalSize = maxTotalSize;
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpackSiloData.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpackSiloData.java
new file mode 100644
index 000000000..338888ada
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/PlayerBackpackSiloData.java
@@ -0,0 +1,45 @@
+package tech.mcprison.prison.backpacks;
+
+import tech.mcprison.prison.internal.ItemStack;
+
+public class PlayerBackpackSiloData {
+
+ private String itemType; // key
+ private ItemStack itemSample; // quantity of 1
+ private int count;
+ private boolean locked; // locks the itemType in to this silo even when count == 0
+
+ public PlayerBackpackSiloData() {
+ super();
+
+ }
+
+ public String getItemType() {
+ return itemType;
+ }
+ public void setItemType(String itemType) {
+ this.itemType = itemType;
+ }
+
+ public ItemStack getItemSample() {
+ return itemSample;
+ }
+ public void setItemSample(ItemStack itemSample) {
+ this.itemSample = itemSample;
+ }
+
+ public int getCount() {
+ return count;
+ }
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public boolean isLocked() {
+ return locked;
+ }
+ public void setLocked(boolean locked) {
+ this.locked = locked;
+ }
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
index e789a2885..aa546845e 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
@@ -12,7 +12,7 @@
import java.util.List;
import tech.mcprison.prison.Prison;
-import tech.mcprison.prison.cache.PlayerCacheFiles;
+import tech.mcprison.prison.cache.CoreCacheFiles;
import tech.mcprison.prison.file.ZipFileIO;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.util.PrisonStatsUtil;
@@ -407,8 +407,8 @@ else if ( file.isFile() ) {
String fName = file.getName();
boolean isDeleteable =
- fName.endsWith( PlayerCacheFiles.FILE_SUFFIX_BACKUP ) ||
- fName.endsWith( PlayerCacheFiles.FILE_SUFFIX_TEMP ) ||
+ fName.endsWith( CoreCacheFiles.FILE_SUFFIX_BACKUP ) ||
+ fName.endsWith( CoreCacheFiles.FILE_SUFFIX_TEMP ) ||
fName.endsWith( ".del" ) ||
fName.startsWith( "_archived_" ) ||
fName.contains( ".json.ver_" ) && fName.endsWith( ".txt" )
diff --git a/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheData.java b/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheData.java
new file mode 100644
index 000000000..6fd790099
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheData.java
@@ -0,0 +1,11 @@
+package tech.mcprison.prison.cache;
+
+import java.io.File;
+
+public interface CoreCacheData {
+
+ public File getPlayerFile();
+
+ public void setPlayerFile( File inputFile );
+
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheFiles.java b/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheFiles.java
new file mode 100644
index 000000000..c8fd65cb1
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/cache/CoreCacheFiles.java
@@ -0,0 +1,435 @@
+package tech.mcprison.prison.cache;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TreeMap;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonSyntaxException;
+
+import tech.mcprison.prison.Prison;
+import tech.mcprison.prison.internal.Player;
+import tech.mcprison.prison.output.Output;
+
+public abstract class CoreCacheFiles {
+
+ public static final String FILE_SUFFIX_JSON = ".json";
+ public static final String FILE_PREFIX_BACKUP = ".backup_";
+ public static final String FILE_SUFFIX_BACKUP = ".bu";
+ public static final String FILE_SUFFIX_TEMP = ".temp";
+ public static final String FILE_TIMESTAMP_FORMAT = "_yyyy-MM-dd_HH-mm-ss";
+
+ private final String cachePath;
+ private File cacheDirectory = null;
+
+ private Gson gson = null;
+ private TreeMap playerFiles;
+
+
+ public CoreCacheFiles( String cachePath ) {
+ super();
+
+ this.cachePath = cachePath;
+ }
+
+ public String getCachePath() {
+ return cachePath;
+ }
+
+ /**
+ *
This constructs the Gson engine using the optional pretty
+ * printing to help make it human readable.
+ *
This loads the PlayerCachePlayerData object from a saved json file.
+ *
+ *
+ *
Since this deals with the actual file name, the "knowledge" on how to
+ * properly generate that file name is contained within this class and should
+ * never be exposed since it may not be correct and can lead to errors.
+ *
This function will take a Prison Player object, and load the correct PlayerCache
+ * file. The file name has a prefix of the first part of the player's UUID and then
+ * followed by the player's name. But it is important to understand that the Player's
+ * name part is totally ignored since player could change their name at any time.
+ *
+ *
+ *
By using the Player's UUID and player name, it constructs the file's full name.
+ * Then it takes the prefix, of the first 14 characters of the UUID, and gets all of
+ * the File objects within the cache directory. Since minecraft UUIDs are generated
+ * from random numbers, the first 14 characters "should" be unique. If the returned
+ * Files are not unique, then each returned File object is loaded so the the correct
+ * file can be selected by the internal UUID. Odds are there will never be duplicates,
+ * but if there is, it will handle it.
+ *
+ *
+ *
If the supplied Player is not in the cache, a new PlayerCachePlayerData object
+ * is created for the player (keyed on the player's UUID and name) and then it is
+ * saved to the cache directory.
+ *
+ *
+ *
Although the Player's file name prefix will always match it's data file, their
+ * name portion of the file can be dynamic. It is important that if the Player changes
+ * their name, that their save cached file will be change within this function.
+ * This process will only happen the first time the player is loaded from the cache
+ * (which can vary, such as at server startup or they logoff and they are cleared from
+ * the cache, then added back when they login the next time). So this function will
+ * rename the cache file to reflect the player's current name.
+ *
+ *
+ * @param player
+ * @return
+ */
+ public CoreCacheData fromJson( Player player, Class extends CoreCacheData> classOfT ) {
+ CoreCacheData results = null;
+
+// // This is the "target" file name for the player, based upon their
+// // current name. The saved cache file may not be named exactly the same,
+// // and if it's not, then their existing cache file will be renamed
+// // within the function getCachedFileMatch()
+ String playerFileName = getPlayerFileName( player );
+
+ File playerFile = getCachedFileMatch( playerFileName );
+
+
+ if ( playerFile.exists() ) {
+
+ results = fromJsonFile( playerFile, classOfT );
+ }
+
+
+ // New player and file does not exist so create it.
+ if ( results == null ) {
+ results = new PlayerCachePlayerData( player, playerFile );
+
+ // Then save it:
+ toJsonFile( results );
+ }
+
+ return results;
+ }
+
+
+ /**
+ *
For generating a json String object from a cache data object type.
+ *
This function serializes the provided core cache data object to the
+ * json file, using the core cache data object as the source for the
+ * json data, and the File object that is stored in that object too.
+ *
+ *
+ *
If the player changes their name while they are online, and if that change
+ * actually percolates through to bukkit, the caching system will never attempt
+ * to change the Player's cached file while it's active. It will rename the
+ * file upon loading in to the cache the next time they are activated.
+ *
+ *
+ *
This function first saves the new player data to a temp file. If that
+ * was successful, then it deletes the original file, and renames the temp
+ * file back to the original name.
+ *
+ *
+ * @param player
+ */
+ public void toJsonFile(CoreCacheData cacheData) {
+
+ if ( cacheData != null ) {
+
+ File playerFile = cacheData.getPlayerFile();
+ File outTemp = createTempFile( playerFile );
+
+ if ( !getPlayerFiles().containsKey( playerFile.getName() )) {
+ getPlayerFiles().put( playerFile.getName(), playerFile );
+ }
+
+ boolean success = false;
+
+ try (
+ FileWriter fw = new FileWriter( outTemp );
+ ){
+ getGson().toJson( cacheData, fw );
+
+ success = true;
+ }
+ catch ( JsonIOException | IOException e ) {
+ e.printStackTrace();
+ }
+
+ // If there is a significant change in file size, or the new file is smaller than the
+ // old, then rename it to a backup and keep it. If it is smaller, then something went wrong
+ // because player cache data should always increase, with the only exception being
+ // the player cache.
+ if ( playerFile.exists() ) {
+ long pfSize = playerFile.length();
+ long tmpSize = outTemp.length();
+
+ if ( tmpSize < pfSize ) {
+
+ renamePlayerFileToBU( playerFile );
+ }
+ }
+
+ if ( success && ( !playerFile.exists() || playerFile.delete()) ) {
+ outTemp.renameTo( playerFile );
+ }
+ else {
+
+ boolean removed = false;
+ if ( outTemp.exists() ) {
+ removed = outTemp.delete();
+ }
+
+ String message = String.format(
+ "Unable to rename PlayerCache temp file. It was %sremoved: %s",
+ (removed ? "" : "not "), outTemp.getAbsolutePath() );
+
+ Output.get().logWarn( message );
+ }
+ }
+ }
+
+ /**
+ *
Constructs a File object for a specific player.
+ *
This function will take the project's data folder and construct the the path
+ * to the directory, if it does not exist, to where the player cache files are stored.
+ *
This function returns the file name which is constructed by
+ * using the player's UUID and their name. The player's name is not
+ * used in the selection of a player's file, only the UUID prefix.
+ *
+ *
+ *
The UUID prefix is based upon the HEX representation of the
+ * the UUID, and includes the first 13 characters which includes one
+ * hyphen. Since the minecraft UUID is based upon random numbers
+ * (type 4 UUID), then odds are great that file name prefixes will
+ * be unique, but they don't have to be.
+ *
+ *
+ *
Its a high importance that file names can be found based upon
+ * Player information, hence the UUID prefix. Plus it's very important
+ * to be able to have the files human readable so admins can find
+ * specific player files if they need to; hence the player name suffix.
+ *
This function returns the first 13 characters of the supplied
+ * file name, or UUID String. The hyphen is around the 12 or 13th position,
+ * so it may or may not include it.
+ *
Potentially there could be more than one result, but considering if a player
+ * changes their name, then it should only return only one entry. The reason for
+ * this, is that the file name should be based upon the player's UUID, which is the
+ * first 13 characters of the file, and the name itself, which follows, should
+ * never be part of the "key".
+ *
+ *
+ * @param playerFile
+ * @param playerFileName
+ * @return
+ */
+ private File getCachedFileMatch( String playerFileName )
+ {
+ File results = null;
+
+ String fileNamePrefix = getFileNamePrefix( playerFileName );
+
+ results = getPlayerFiles().get( fileNamePrefix );
+
+ if ( results == null ) {
+
+ // This is the "target" file name for the player, based upon their
+ // current name. The saved cache file may not be named exactly the same,
+ // and if it's not, then their existing cache file needs to be
+ // renamed.
+ results = getPlayerFile( playerFileName );
+
+ // NOTE: because the file was NOT found in the directory, then we can assume
+ // this is a new player therefore we won't have an issue with the player's
+ // name changing.
+ getPlayerFiles().put( fileNamePrefix, results );
+ }
+ else if ( !playerFileName.equalsIgnoreCase( results.getName() )) {
+
+ // File name changed!!! Need to rename the file in the file system, and
+ // update what is in the playerFiles map!!
+
+ File newFile = getPlayerFile( playerFileName );
+
+ if ( results.exists() ) {
+ // rename what's on the file system:
+ results.renameTo( newFile );
+ }
+
+ // Replace what's in the map:
+ getPlayerFiles().put( fileNamePrefix, newFile );
+
+ results = newFile;
+ }
+
+// NavigableMap files = getPlayerFiles().tailMap( fileNamePrefix, true );
+// Set keys = files.keySet();
+// for ( String key : keys ) {
+// if ( !key.startsWith( fileNamePrefix ) ) {
+// break;
+// }
+//
+// results.add( files.get( key ) );
+// }
+
+ return results;
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCacheFiles.java b/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCacheFiles.java
index db120784f..ee99ba8bb 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCacheFiles.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCacheFiles.java
@@ -1,22 +1,6 @@
package tech.mcprison.prison.cache;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TreeMap;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonIOException;
-import com.google.gson.JsonSyntaxException;
-
-import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.Player;
-import tech.mcprison.prison.output.Output;
/**
*
This class is intended to be kept online and active for the full
@@ -35,415 +19,21 @@
*
*/
public class PlayerCacheFiles
+ extends CoreCacheFiles
{
- public static final String FILE_SUFFIX_JSON = ".json";
- public static final String FILE_PREFIX_BACKUP = ".backup_";
- public static final String FILE_SUFFIX_BACKUP = ".bu";
- public static final String FILE_SUFFIX_TEMP = ".temp";
- public static final String FILE_TIMESTAMP_FORMAT = "_yyyy-MM-dd_HH-mm-ss";
- public static final String FILE_PLAYERCACHE_PATH = "data_storage/playerCache";
-
-
- private Gson gson = null;
-
- private File playerCacheDirectory = null;
-
-
- private TreeMap playerFiles;
+ public static final String FILE_PLAYER_CACHE_PATH = "data_storage/playerCache";
public PlayerCacheFiles() {
- super();
-
- }
-
- /**
- *
This constructs the Gson engine using the optional pretty
- * printing to help make it human readable.
- *
For generating a json String object from the player's data.
- *
- *
- * @param player
- * @return
- */
- public String toJson( PlayerCachePlayerData player ) {
- return getGson().toJson( player );
- }
-
- /**
- *
This function serializes the provided Player's object to the
- * json file, using the player data object as the source for the
- * json data, and the File object that is stored in that object too.
- *
- *
- *
If the player changes their name while they are online, and if that change
- * actually percolates through to bukkit, the caching system will never attempt
- * to change the Player's cached file while it's active. It will rename the
- * file upon loading in to the cache the next time they are activated.
- *
- *
- *
This function first saves the new player data to a temp file. If that
- * was successful, then it deletes the original file, and renames the temp
- * file back to the original name.
- *
- *
- * @param player
- */
- public void toJsonFile( PlayerCachePlayerData player) {
-
- if ( player != null ) {
-
- File playerFile = player.getPlayerFile();
- File outTemp = createTempFile( playerFile );
-
- if ( !getPlayerFiles().containsKey( playerFile.getName() )) {
- getPlayerFiles().put( playerFile.getName(), playerFile );
- }
-
- boolean success = false;
-
- try (
- FileWriter fw = new FileWriter( outTemp );
- ){
- getGson().toJson( player, fw );
-
- success = true;
- }
- catch ( JsonIOException | IOException e ) {
- e.printStackTrace();
- }
-
- // If there is a significant change in file size, or the new file is smaller than the
- // old, then rename it to a backup and keep it. If it is smaller, then something went wrong
- // because player cache data should always increase, with the only exception being
- // the player cache.
- if ( playerFile.exists() ) {
- long pfSize = playerFile.length();
- long tmpSize = outTemp.length();
-
- if ( tmpSize < pfSize ) {
-
- renamePlayerFileToBU( playerFile );
- }
- }
-
- if ( success && ( !playerFile.exists() || playerFile.delete()) ) {
- outTemp.renameTo( playerFile );
- }
- else {
-
- boolean removed = false;
- if ( outTemp.exists() ) {
- removed = outTemp.delete();
- }
-
- String message = String.format(
- "Unable to rename PlayerCache temp file. It was %sremoved: %s",
- (removed ? "" : "not "), outTemp.getAbsolutePath() );
-
- Output.get().logWarn( message );
- }
- }
- }
-
- private void renamePlayerFileToBU( File playerFile )
- {
- String buFileName = FILE_PREFIX_BACKUP +
- playerFile.getName().replace( FILE_SUFFIX_TEMP, FILE_SUFFIX_BACKUP );
-
- File backupFile = new File( playerFile.getParent(), buFileName );
-
- playerFile.renameTo( backupFile );
+ super( FILE_PLAYER_CACHE_PATH );
}
- private File createTempFile( File file ) {
- SimpleDateFormat sdf = new SimpleDateFormat( FILE_TIMESTAMP_FORMAT );
- String name = file.getName() + sdf.format( new Date() ) + FILE_SUFFIX_TEMP;
-
- return new File( file.getParentFile(), name);
- }
-
- /**
- *
This loads the PlayerCachePlayerData object from a saved json file.
- *
- *
- *
Since this deals with the actual file name, the "knowledge" on how to
- * properly generate that file name is contained within this class and should
- * never be exposed since it may not be correct and can lead to errors.
- *
This function returns the file name which is constructed by
- * using the player's UUID and their name. The player's name is not
- * used in the selection of a player's file, only the UUID prefix.
- *
- *
- *
The UUID prefix is based upon the HEX representation of the
- * the UUID, and includes the first 13 characters which includes one
- * hyphen. Since the minecraft UUID is based upon random numbers
- * (type 4 UUID), then odds are great that file name prefixes will
- * be unique, but they don't have to be.
- *
- *
- *
Its a high importance that file names can be found based upon
- * Player information, hence the UUID prefix. Plus it's very important
- * to be able to have the files human readable so admins can find
- * specific player files if they need to; hence the player name suffix.
- *
This function returns the first 13 characters of the supplied
- * file name, or UUID String. The hyphen is around the 12 or 13th position,
- * so it may or may not include it.
- *
This function will take the project's data folder and construct the the path
- * to the directory, if it does not exist, to where the player cache files are stored.
- *
This function will take a Prison Player object, and load the correct PlayerCache
- * file. The file name has a prefix of the first part of the player's UUID and then
- * followed by the player's name. But it is important to understand that the Player's
- * name part is totally ignored since player could change their name at any time.
- *
- *
- *
By using the Player's UUID and player name, it constructs the file's full name.
- * Then it takes the prefix, of the first 14 characters of the UUID, and gets all of
- * the File objects within the cache directory. Since minecraft UUIDs are generated
- * from random numbers, the first 14 characters "should" be unique. If the returned
- * Files are not unique, then each returned File object is loaded so the the correct
- * file can be selected by the internal UUID. Odds are there will never be duplicates,
- * but if there is, it will handle it.
- *
- *
- *
If the supplied Player is not in the cache, a new PlayerCachePlayerData object
- * is created for the player (keyed on the player's UUID and name) and then it is
- * saved to the cache directory.
- *
- *
- *
Although the Player's file name prefix will always match it's data file, their
- * name portion of the file can be dynamic. It is important that if the Player changes
- * their name, that their save cached file will be change within this function.
- * This process will only happen the first time the player is loaded from the cache
- * (which can vary, such as at server startup or they logoff and they are cleared from
- * the cache, then added back when they login the next time). So this function will
- * rename the cache file to reflect the player's current name.
- *
- *
- * @param player
- * @return
- */
public PlayerCachePlayerData fromJson( Player player ) {
- PlayerCachePlayerData results = null;
-
-// // This is the "target" file name for the player, based upon their
-// // current name. The saved cache file may not be named exactly the same,
-// // and if it's not, then their existing cache file will be renamed
-// // within the function getCachedFileMatch()
- String playerFileName = getPlayerFileName( player );
-
- File playerFile = getCachedFileMatch( playerFileName );
-
-
- if ( playerFile.exists() ) {
-
- results = fromJsonFile( playerFile );
- }
-
-
- // New player and file does not exist so create it.
- if ( results == null ) {
- results = new PlayerCachePlayerData( player, playerFile );
-
- // Then save it:
- toJsonFile( results );
- }
-
- return results;
- }
-
-
-
- private TreeMap getPlayerFiles() {
- // load the player's files:
- if ( playerFiles == null ) {
-
- playerFiles = new TreeMap<>();
-
- FileFilter fileFilter = (file) -> {
-
- String fname = file.getName();
- boolean isTemp = fname.startsWith( FILE_PREFIX_BACKUP ) ||
- fname.endsWith( FILE_SUFFIX_BACKUP ) ||
- fname.endsWith( FILE_SUFFIX_TEMP );
-
- return !file.isDirectory() && !isTemp &&
- fname.endsWith( FILE_SUFFIX_JSON );
- };
-
-
- File[] files = getPlayerFilePath().listFiles( fileFilter );
- for ( File f : files )
- {
- String fileNamePrefix = getFileNamePrefix( f.getName() );
- getPlayerFiles().put( fileNamePrefix, f );
- }
-
- }
-
- return playerFiles;
- }
-
- /**
- *
Potentially there could be more than one result, but considering if a player
- * changes their name, then it should only return only one entry. The reason for
- * this, is that the file name should be based upon the player's UUID, which is the
- * first 13 characters of the file, and the name itself, which follows, should
- * never be part of the "key".
- *
- *
- * @param playerFile
- * @param playerFileName
- * @return
- */
- private File getCachedFileMatch( String playerFileName )
- {
- File results = null;
-
- String fileNamePrefix = getFileNamePrefix( playerFileName );
-
- results = getPlayerFiles().get( fileNamePrefix );
-
- if ( results == null ) {
-
- // This is the "target" file name for the player, based upon their
- // current name. The saved cache file may not be named exactly the same,
- // and if it's not, then their existing cache file needs to be
- // renamed.
- results = getPlayerFile( playerFileName );
-
- // NOTE: because the file was NOT found in the directory, then we can assume
- // this is a new player therefore we won't have an issue with the player's
- // name changing.
- getPlayerFiles().put( fileNamePrefix, results );
- }
- else if ( !playerFileName.equalsIgnoreCase( results.getName() )) {
-
- // File name changed!!! Need to rename the file in the file system, and
- // update what is in the playerFiles map!!
-
- File newFile = getPlayerFile( playerFileName );
-
- if ( results.exists() ) {
- // rename what's on the file system:
- results.renameTo( newFile );
- }
-
- // Replace what's in the map:
- getPlayerFiles().put( fileNamePrefix, newFile );
-
- results = newFile;
- }
-// NavigableMap files = getPlayerFiles().tailMap( fileNamePrefix, true );
-// Set keys = files.keySet();
-// for ( String key : keys ) {
-// if ( !key.startsWith( fileNamePrefix ) ) {
-// break;
-// }
-//
-// results.add( files.get( key ) );
-// }
+ CoreCacheData results = fromJson( player, PlayerCachePlayerData.class );
- return results;
+ return (PlayerCachePlayerData) results;
}
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCachePlayerData.java b/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCachePlayerData.java
index cf33074ca..9352102c8 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCachePlayerData.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/cache/PlayerCachePlayerData.java
@@ -24,7 +24,8 @@
* @author RoyalBlueRanger
*
*/
-public class PlayerCachePlayerData {
+public class PlayerCachePlayerData
+ implements CoreCacheData {
public static final long SESSION_TIMEOUT_MINING_MS = 1000 * 15; // 15 seconds
From 0744493dbbf6937b0decdc3240b8228de5ab5a56 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 10 Sep 2022 01:20:28 -0400
Subject: [PATCH 018/129] Changed the command `/mines set notification` to work
with both disable and disabled.
---
docs/changelog_v3.3.x.md | 3 +++
.../tech/mcprison/prison/mines/commands/MinesCommands.java | 2 +-
.../main/java/tech/mcprison/prison/mines/data/MineData.java | 5 +++++
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 9f510c1df..5c413ff28 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -15,6 +15,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13b 2022-09-10
+* **Changed the command `/mines set notification` to work with both disable and disabled.**
+
+
* **Initial setup of BackpackCache code. Not test. Not hooked up yet to anything. But the cache should be functional.**
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
index ca9bae237..dd715c0a0 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
@@ -2078,7 +2078,7 @@ public void setNotificationCommand(CommandSender sender,
@Arg(name = "mineName", description = "The name of the mine to edit, or '*all*' to "
+ "apply to all mines. [*all*]") String mineName,
@Arg(name = "mode", def="displayOptions", description = "The notification mode "
- + "to use: disabled, within, radius")
+ + "to use: [disabled within radius]")
String mode,
@Arg(name = "radius", def="0", description = "The distance from the center of the mine to notify players of a reset." )
String radius
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
index 249892b60..4de25c311 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
@@ -164,6 +164,7 @@ public abstract class MineData
public enum MineNotificationMode {
disabled,
+ disable,
within,
radius,
@@ -184,6 +185,10 @@ public static MineNotificationMode fromString(String mode, MineNotificationMode
}
}
+ if ( results == disable ) {
+ results = disabled;
+ }
+
return results;
}
}
From fb8866c419744efa6bf4b8b295c146838dd1aa88 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 10 Sep 2022 13:31:57 -0400
Subject: [PATCH 019/129] Refactor Prison's old backpacks to reduce duplicate
code to prepare for use of the BackpackCache.
---
docs/changelog_v3.3.x.md | 3 +
.../mcprison/prison/spigot/SpigotUtil.java | 18 +-
.../spigot/backpacks/BackpacksUtil.java | 312 ++++++++++--------
.../PrisonSpigotBackpackCommands.java | 5 +-
.../spigot/gui/ListenersPrisonManager.java | 3 +-
.../prison/spigot/sellall/SellAllUtil.java | 7 +-
6 files changed, 201 insertions(+), 147 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 5c413ff28..5b42a9d70 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -15,6 +15,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13b 2022-09-10
+* **Refactor Prison's old backpacks to reduce duplicate code to prepare for use of the BackpackCache.**
+
+
* **Changed the command `/mines set notification` to work with both disable and disabled.**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
index 40d0eab94..ee35d732c 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
@@ -249,19 +249,20 @@ public static HashMap addItemToPlayerInventory(
if (bpUtil.isMultipleBackpacksEnabled()) {
for (String id : bpUtil.getBackpacksIDs(player)) {
if (overflow.size() > 0) {
- if (id == null) {
- Inventory inv = bpUtil.getBackpack(player);
- overflow = inv.addItem(overflow.values().toArray(new ItemStack[0]));
- bpUtil.setInventory(player, inv);
- } else {
+// if (id == null) {
+// Inventory inv = bpUtil.getBackpack(player);
+// overflow = inv.addItem(overflow.values().toArray(new ItemStack[0]));
+// bpUtil.setInventory(player, inv);
+// } else {
Inventory inv = bpUtil.getBackpack(player, id);
overflow = inv.addItem(overflow.values().toArray(new ItemStack[0]));
bpUtil.setInventory(player, inv, id);
- }
+// }
}
}
} else {
- Inventory inv = bpUtil.getBackpack(player);
+ String id = null;
+ Inventory inv = bpUtil.getBackpack(player, id);
overflow = inv.addItem(overflow.values().toArray(new ItemStack[0]));
bpUtil.setInventory(player, inv);
}
@@ -386,7 +387,8 @@ public static int itemStackRemoveAll(Player player, XMaterial xMat ) {
// Insert overflow in to Prison's backpack:
if ( SpigotPrison.getInstance().getConfig().getString("backpacks").equalsIgnoreCase("true")) {
- Inventory inv = BackpacksUtil.get().getBackpack(player);
+ String id = null;
+ Inventory inv = BackpacksUtil.get().getBackpack(player, id);
removed += itemStackRemoveAll( xMat, inv );
BackpacksUtil.get().setInventory( player, inv );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
index 97542afce..f54c75827 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
@@ -27,7 +27,6 @@
import tech.mcprison.prison.spigot.SpigotUtil;
import tech.mcprison.prison.spigot.compat.Compatibility;
import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
-import tech.mcprison.prison.spigot.configs.BackpacksConfig;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
/**
@@ -303,16 +302,16 @@ public void setBackpackSize(OfflinePlayer p, int size, String id){
backpackResize(p, size, id);
}
- /**
- * Get a backpack size depending on the owner.
- *
- * @param p - Player
- *
- * @return backPackSize - Integer
- * */
- public int getBackpackSize(Player p){
- return getSize(p);
- }
+// /**
+// * Get a backpack size depending on the owner.
+// *
+// * @param p - Player
+// *
+// * @return backPackSize - Integer
+// * */
+// public int getBackpackSize(Player p){
+// return getSize(p);
+// }
/**
* Get a backpack size depending on the owner.
@@ -326,6 +325,26 @@ public int getBackpackSize(Player p, String id){
return getSize(p, id);
}
+// /**
+// * Get Prison Backpacks Inventory.
+// * Also if you need to modify it you can do it just by using BackPacksUtil getInventory(player)
+// * modify your inventory as you'd usually with spigot inventories
+// * and then use BackPacksUtil setInventory(player, inventory) is recommended.
+// *
+// * EXAMPLE for adding item:
+// * Inventory inv = BackPacksUtil.getInventory(p);
+// * ItemStack item = new ItemStack(Material.COAL_ORE, 1);
+// * inv.addItem(item)
+// * BackPacksUtil.setInventory(inv);
+// *
+// * @param p - player
+// *
+// * @return inv - Inventory/Backpack.
+// * */
+// public Inventory getBackpack(Player p){
+// return getBackpackOwn(p, null);
+// }
+
/**
* Get Prison Backpacks Inventory.
* Also if you need to modify it you can do it just by using BackPacksUtil getInventory(player)
@@ -338,15 +357,6 @@ public int getBackpackSize(Player p, String id){
* inv.addItem(item)
* BackPacksUtil.setInventory(inv);
*
- * @param p - player
- *
- * @return inv - Inventory/Backpack.
- * */
- public Inventory getBackpack(Player p){
- return getBackpackOwn(p);
- }
-
- /**
* Get Prison backpack of a Player + ID, because a player can have more than one Inventory.
*
* @param p - Player
@@ -358,14 +368,15 @@ public Inventory getBackpack(Player p, String id){
return getBackpackOwn(p, id);
}
- /**
- * Open backpack.
- *
- * @param p - Player
- * */
- public void openBackpack(Player p){
- openBackpackMethod(p);
- }
+// /**
+// * Open backpack.
+// *
+// * @param p - Player
+// * */
+// public void openBackpack(Player p){
+// String id = null;
+// openBackpackMethod(p, id);
+// }
/**
* Open backpack by ID.
@@ -734,11 +745,11 @@ private boolean backpacksLimitSet(OfflinePlayer p, int limit) {
return true;
}
- private void backpackConfigUpdater() {
- BackpacksConfig bpTemp = new BackpacksConfig();
- bpTemp.initialize();
- backpacksConfig = bpTemp.getFileBackpacksConfig();
- }
+// private void backpackConfigUpdater() {
+// BackpacksConfig bpTemp = new BackpacksConfig();
+// bpTemp.initialize();
+// backpacksConfig = bpTemp.getFileBackpacksConfig();
+// }
private static BackpacksUtil getInstance() {
if (instance == null && SpigotPrison.getInstance().getConfig().getString("backpacks") != null && SpigotPrison.getInstance().getConfig().getString("backpacks").equalsIgnoreCase("true")){
@@ -942,31 +953,36 @@ private void backpackResize(OfflinePlayer p, int size, String id) {
updateCachedBackpack();
}
- private int getSize(Player p) {
- updateCachedBackpack();
-
- int backPackSize = backpackDefaultSize;
-
- try {
- backPackSize = Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items.Size"));
- } catch (NumberFormatException ignored){}
-
- if (backPackSize % 9 != 0){
- backPackSize = (int) Math.ceil((float)backPackSize / 9) * 9;
- }
-
- if (backPackSize == 0) backPackSize = 9;
-
- return getBackpackPermSize(p, backPackSize);
- }
+// private int getSize(Player p) {
+// updateCachedBackpack();
+//
+// int backPackSize = backpackDefaultSize;
+//
+// try {
+// backPackSize = Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items.Size"));
+// } catch (NumberFormatException ignored){}
+//
+// if (backPackSize % 9 != 0){
+// backPackSize = (int) Math.ceil((float)backPackSize / 9) * 9;
+// }
+//
+// if (backPackSize == 0) backPackSize = 9;
+//
+// return getBackpackPermSize(p, backPackSize);
+// }
private int getSize(Player p, String id) {
+ String backpackId = id == null ?
+ "" : "-" + id;
+
updateCachedBackpack();
int backPackSize = backpackDefaultSize;
try {
- backPackSize = Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items-" + id + ".Size"));
+ String size = backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + backpackId + ".Size");
+
+ backPackSize = Integer.parseInt( size );
} catch (NumberFormatException ignored){}
if (backPackSize % 9 != 0){
@@ -995,51 +1011,57 @@ private int getBackpackPermSize(Player p, int backPackSize) {
return backPackSize;
}
- private Inventory getBackpackOwn(Player p) {
-
- updateCachedBackpack();
-
- int size = getBackpackSize(p);
- Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack"));
-
- // Get the Items config section
- Set slots;
- try {
- slots = backpacksDataConfig.getConfigurationSection("Inventories." + p.getUniqueId() + ".Items").getKeys(false);
- } catch (NullPointerException ex){
- return inv;
- }
- if (slots.size() != 0) {
- for (String slot : slots) {
- ItemStack finalItem = backpacksDataConfig.getItemStack("Inventories." + p.getUniqueId() + ".Items." + slot + ".ITEMSTACK");
- if (finalItem != null) {
- int slotNumber = Integer.parseInt(slot);
- if (size > slotNumber) {
- inv.setItem(slotNumber, finalItem);
- }
- }
- }
- }
-
- return inv;
- }
+// private Inventory getBackpackOwn(Player p) {
+//
+// updateCachedBackpack();
+//
+// int size = getBackpackSize(p, null);
+// Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack"));
+//
+// // Get the Items config section
+// Set slots;
+// try {
+// slots = backpacksDataConfig.getConfigurationSection("Inventories." + p.getUniqueId() + ".Items").getKeys(false);
+// } catch (NullPointerException ex){
+// return inv;
+// }
+// if (slots.size() != 0) {
+// for (String slot : slots) {
+// ItemStack finalItem = backpacksDataConfig.getItemStack("Inventories." + p.getUniqueId() + ".Items." + slot + ".ITEMSTACK");
+// if (finalItem != null) {
+// int slotNumber = Integer.parseInt(slot);
+// if (size > slotNumber) {
+// inv.setItem(slotNumber, finalItem);
+// }
+// }
+// }
+// }
+//
+// return inv;
+// }
private Inventory getBackpackOwn(Player p, String id) {
+ String backpackId = id == null ?
+ "" : "-" + id;
+
updateCachedBackpack();
int size = getBackpackSize(p, id);
- Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack-" + id));
+
+ Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack" + backpackId));
// Get the Items config section
Set slots;
try {
- slots = backpacksDataConfig.getConfigurationSection("Inventories." + p.getUniqueId() + ".Items-" + id).getKeys(false);
+ slots = backpacksDataConfig.getConfigurationSection(
+ "Inventories." + p.getUniqueId() + ".Items" + backpackId).getKeys(false);
} catch (NullPointerException ex){
return inv;
}
if (slots.size() != 0) {
for (String slot : slots) {
- ItemStack finalItem = backpacksDataConfig.getItemStack("Inventories." + p.getUniqueId() + ".Items-" + id + "." + slot + ".ITEMSTACK");
+ ItemStack finalItem = backpacksDataConfig.getItemStack(
+ "Inventories." + p.getUniqueId() + ".Items" + backpackId + "." + slot + ".ITEMSTACK");
if (finalItem != null) {
int slotNumber = Integer.parseInt(slot);
if (size > slotNumber) {
@@ -1052,14 +1074,15 @@ private Inventory getBackpackOwn(Player p, String id) {
return inv;
}
- private void openBackpackMethod(Player p) {
- playOpenBackpackSound(p);
- Inventory inv = getBackpack(p);
- p.openInventory(inv);
- if (!openBackpacks.contains(p.getName())){
- openBackpacks.add(p.getName());
- }
- }
+// private void openBackpackMethod(Player p) {
+// playOpenBackpackSound(p);
+// String id = null;
+// Inventory inv = getBackpack(p, id);
+// p.openInventory(inv);
+// if (!openBackpacks.contains(p.getName())){
+// openBackpacks.add(p.getName());
+// }
+// }
private void openBackpackMethod(Player p, String id) {
playOpenBackpackSound(p);
@@ -1098,13 +1121,13 @@ private void saveInventory(Player p, Inventory inv) {
updateCachedBackpack();
// Set dimensions if null or error.
- boolean needToSetNewDimensions = checkDimensionError(p);
+ boolean needToSetNewDimensions = checkDimensionError(p, null);
boolean needToSetNewOwner = checkBackpackOwnerMissing(p);
boolean needToSetNewOwnerID = checkBackpackOwnerIDMissing(p);
if (inv.getContents() != null){
- int backpackSize = getBackpackSize(p);
+ int backpackSize = getBackpackSize(p, null);
int slot = 0;
try {
@@ -1128,7 +1151,7 @@ private void saveInventory(Player p, Inventory inv) {
}
}
- oldDataVersionUpdater(p, false, true, true);
+ oldDataVersionUpdater(p, null, false, true, true);
try {
backpacksDataConfig.save(backpacksFile);
@@ -1137,7 +1160,7 @@ private void saveInventory(Player p, Inventory inv) {
}
} else {
// If it's null just delete the whole stored inventory.
- oldDataVersionUpdater(p, needToSetNewDimensions, needToSetNewOwner, needToSetNewOwnerID);
+ oldDataVersionUpdater(p, null, needToSetNewDimensions, needToSetNewOwner, needToSetNewOwnerID);
try {
backpacksDataConfig.set("Inventories." + p.getUniqueId().toString() + ".Items", null);
backpacksDataConfig.save(backpacksFile);
@@ -1150,12 +1173,15 @@ private void saveInventory(Player p, Inventory inv) {
}
private void saveInventory(Player p, Inventory inv, String id) {
+ String backpackId = id == null ?
+ "" : "-" + id;
+
updateCachedBackpack();
// Set dimensions if null or error.
boolean needToSetNewDimensions = checkDimensionError(p, id);
- boolean needToSetNewOwner = checkBackpackOwnerMissing(p, id);
- boolean needToSetNewOwnerID = checkBackpackOwnerIDMissing(p, id);
+ boolean needToSetNewOwner = checkBackpackOwnerMissing(p);
+ boolean needToSetNewOwnerID = checkBackpackOwnerIDMissing(p);
if (inv.getContents() != null){
@@ -1163,7 +1189,7 @@ private void saveInventory(Player p, Inventory inv, String id) {
int slot = 0;
try {
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items-" + id, null);
+ backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items" + backpackId, null);
backpacksDataConfig.save(backpacksFile);
} catch (IOException ex){
ex.printStackTrace();
@@ -1172,14 +1198,14 @@ private void saveInventory(Player p, Inventory inv, String id) {
updateCachedBackpack();
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items-" + id + ".Size", backpackSize);
+ backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items" + backpackId + ".Size", backpackSize);
oldDataVersionUpdater(p, id, false, true, true);
for (ItemStack item : inv.getContents()){
if (item != null){
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items-" + id + "." + slot + ".ITEMSTACK", item);
+ backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items" + backpackId + "." + slot + ".ITEMSTACK", item);
slot++;
}
@@ -1195,7 +1221,7 @@ private void saveInventory(Player p, Inventory inv, String id) {
// If it's null just delete the whole stored inventory.
oldDataVersionUpdater(p, id, needToSetNewDimensions, needToSetNewOwner, needToSetNewOwnerID);
try {
- backpacksDataConfig.set("Inventories." + p.getUniqueId().toString() + ".Items-" + id, null);
+ backpacksDataConfig.set("Inventories." + p.getUniqueId().toString() + ".Items" + backpackId, null);
backpacksDataConfig.save(backpacksFile);
} catch (IOException ex){
ex.printStackTrace();
@@ -1205,21 +1231,26 @@ private void saveInventory(Player p, Inventory inv, String id) {
updateCachedBackpack();
}
- private void oldDataVersionUpdater(Player p, boolean needToSetNewDimensions, boolean needToSetNewOwner, boolean needToSetNewOwnerID) {
- if (needToSetNewDimensions){
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items.Size", Integer.parseInt(backpacksConfig.getString("Options.BackPack_Default_Size")));
- }
- if (needToSetNewOwner){
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".PlayerName", p.getName());
- }
- if (needToSetNewOwnerID){
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".UniqueID", p.getUniqueId().toString());
- }
- }
+// private void oldDataVersionUpdater(Player p, boolean needToSetNewDimensions, boolean needToSetNewOwner, boolean needToSetNewOwnerID) {
+// if (needToSetNewDimensions){
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items.Size",
+// Integer.parseInt(backpacksConfig.getString("Options.BackPack_Default_Size")));
+// }
+// if (needToSetNewOwner){
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".PlayerName", p.getName());
+// }
+// if (needToSetNewOwnerID){
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".UniqueID", p.getUniqueId().toString());
+// }
+// }
private void oldDataVersionUpdater(Player p, String id, boolean needToSetNewDimensions, boolean needToSetNewOwner, boolean needToSetNewOwnerID) {
- if (needToSetNewDimensions){
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items-" + id + ".Size", Integer.parseInt(backpacksConfig.getString("Options.BackPack_Default_Size")));
+ String backpackId = id == null ?
+ "" : "-" + id;
+
+ if (needToSetNewDimensions){
+ backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items" + backpackId + ".Size",
+ Integer.parseInt(backpacksConfig.getString("Options.BackPack_Default_Size")));
}
if (needToSetNewOwner){
backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".PlayerName", p.getName());
@@ -1230,7 +1261,8 @@ private void oldDataVersionUpdater(Player p, String id, boolean needToSetNewDime
}
private HashMap addItemToBackpack(Player p, ItemStack item) {
- Inventory inv = getBackpack(p);
+ String id = null;
+ Inventory inv = getBackpack(p, id);
HashMap overflow = inv.addItem(item);
setInventory(p, inv);
return overflow;
@@ -1244,7 +1276,8 @@ private HashMap addItemToBackpack(Player p, ItemStack item,
}
private HashMap removeItemFromBackpack(Player p, ItemStack item) {
- Inventory inv = getBackpack(p);
+ String id = null;
+ Inventory inv = getBackpack(p, id );
HashMap underflow = inv.removeItem(item);
setInventory(p, inv);
return underflow;
@@ -1356,24 +1389,35 @@ private int getNumberOfBackpacksOwnedByPlayer(Player p) {
return backpacksNumber;
}
- private boolean checkDimensionError(Player p) {
- try{
- if (backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + ".Size") == null){
- return true;
- }
- Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + ".Size"));
- } catch (NumberFormatException ex){
- return true;
- }
- return false;
- }
+// private boolean checkDimensionError(Player p) {
+// try{
+// if (backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + ".Size") == null){
+// return true;
+// }
+// Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + ".Size"));
+// } catch (NumberFormatException ex){
+// return true;
+// }
+// return false;
+// }
+ /**
+ * This function ONLY checks to confirm if the config setting is an integer!? \
+ *
+ * @param p
+ * @param id
+ * @return
+ */
private boolean checkDimensionError(Player p, String id) {
+ String backpackId = id == null ?
+ "" : "-" + id;
try{
- if (backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items-" + id + ".Size") == null){
+ String size = backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items" + backpackId + ".Size");
+
+ if ( size == null){
return true;
}
- Integer.parseInt(backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".Items-" + id + ".Size"));
+ Integer.parseInt( size );
} catch (NumberFormatException ex){
return true;
}
@@ -1384,17 +1428,17 @@ private boolean checkBackpackOwnerMissing(Player p) {
return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".PlayerName") == null;
}
- private boolean checkBackpackOwnerMissing(Player p, String id) {
- return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".PlayerName") == null;
- }
+// private boolean checkBackpackOwnerMissing(Player p, String id) {
+// return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".PlayerName") == null;
+// }
private boolean checkBackpackOwnerIDMissing(Player p) {
return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".UniqueID") == null;
}
- private boolean checkBackpackOwnerIDMissing(Player p, String id) {
- return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".UniqueID") == null;
- }
+// private boolean checkBackpackOwnerIDMissing(Player p, String id) {
+// return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".UniqueID") == null;
+// }
private OfflinePlayer getOfflinePlayer(String name) {
if (name != null) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
index 9913c3c4d..17485d1f0 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
@@ -273,7 +273,8 @@ private void openBackpackAdminGUI(CommandSender sender){
@Command(identifier = "gui backpack", description = "Backpack as a GUI", onlyPlayers = true)
private void backpackGUIOpenCommand(CommandSender sender,
- @Arg(name = "Backpack-ID", def = "null", description = "If user have more than backpack, he'll be able to choose another backpack on ID") String id){
+ @Arg(name = "Backpack-ID", def = "null",
+ description = "If user have more than backpack, he'll be able to choose another backpack on ID") String id){
Player p = getSpigotPlayer(sender);
@@ -303,7 +304,7 @@ private void backpackGUIOpenCommand(CommandSender sender,
if (!id.equalsIgnoreCase("null") && getBoolean(BackpacksUtil.get().getBackpacksConfig().getString("Options.Multiple-BackPacks-For-Player-Enabled"))){
BackpacksUtil.get().openBackpack(p, id);
} else {
- BackpacksUtil.get().openBackpack(p);
+ BackpacksUtil.get().openBackpack(p, (String) null );
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
index b3c028de7..ed4102bf9 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/ListenersPrisonManager.java
@@ -842,7 +842,8 @@ private void backpacksList(Player p, String buttonNameMain, String[] parts) {
}
} else if (buttonNameMain.equalsIgnoreCase("Backpack")){
- BackpacksUtil.get().openBackpack(p);
+ String id = null;
+ BackpacksUtil.get().openBackpack(p, id);
} else {
BackpacksUtil.get().openBackpack(p, buttonNameMain.substring(9));
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
index 66296e8c2..8d01187cb 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
@@ -558,7 +558,9 @@ private HashMap getHashMapOfPlayerInventories(Player p) {
xMaterialIntegerHashMap = addInventoryToHashMap(xMaterialIntegerHashMap, backpacksUtil.getBackpack(p, id));
}
} else {
- xMaterialIntegerHashMap = addInventoryToHashMap(xMaterialIntegerHashMap, backpacksUtil.getBackpack(p));
+ String id = null;
+ xMaterialIntegerHashMap = addInventoryToHashMap(xMaterialIntegerHashMap,
+ backpacksUtil.getBackpack(p, id));
}
}
@@ -1459,7 +1461,8 @@ public void removeSellableItems(Player p){
backpacksUtil.setInventory(p, removeSellableItems(p, backpacksUtil.getBackpack(p, id)), id);
}
} else {
- backpacksUtil.setInventory(p, removeSellableItems(p, backpacksUtil.getBackpack(p)));
+ String id = null;
+ backpacksUtil.setInventory(p, removeSellableItems(p, backpacksUtil.getBackpack(p, id)));
}
}
From 6e8edb3bac453947556d152422f9f1a306a84cb2 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 14 Sep 2022 20:03:48 -0400
Subject: [PATCH 020/129] More refactoring of the old backpacks to get rid of
bad code to make it easier to integrate in to a newer backpack framework.
---
docs/changelog_v3.3.x.md | 6 +-
.../prison/backpacks/BackpackEnums.java | 7 +-
.../mcprison/prison/spigot/SpigotUtil.java | 4 +-
.../spigot/backpacks/BackpacksListeners.java | 30 +-
.../spigot/backpacks/BackpacksUtil.java | 313 +++++++++---------
.../PrisonSpigotBackpackCommands.java | 41 ++-
.../prison/spigot/sellall/SellAllUtil.java | 2 +-
7 files changed, 214 insertions(+), 189 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 5b42a9d70..be5a769b2 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-09-10
+# 3.3.0-alpha.13b 2022-09-14
+
+
+* **More refactoring of the old backpacks to get rid of bad code to make it easier to integrate in to a newer backpack framework.**
+No behavioral changes should have occurred with this commit, and the prior commit too.
* **Refactor Prison's old backpacks to reduce duplicate code to prepare for use of the BackpackCache.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java
index c193f3766..ffccc9333 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/backpacks/BackpackEnums.java
@@ -18,6 +18,11 @@ public enum BackpackFeatures {
enablePlayerToggle, // player pickup toggleable
enableSellallToggle, // player sellall toggleable
enchanted, // show enchant glow on item
- placeable; // Able to place backpack as a chest - may need to supply empty chests
+ placeable, // Able to place backpack as a chest - may need to supply empty chests
+
+ allowMultiples, // If this feature is not set, then a player can only have one backpack of a given type
+ loreStats, // Update lore on backpack item with stats: blocks and counts
+ restrictView, // Prevent viewing through open inventory. Use with loreStats.
+ allowRename, // Allow players to rename their backpacks
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
index ee35d732c..e991cbefd 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotUtil.java
@@ -264,7 +264,7 @@ public static HashMap addItemToPlayerInventory(
String id = null;
Inventory inv = bpUtil.getBackpack(player, id);
overflow = inv.addItem(overflow.values().toArray(new ItemStack[0]));
- bpUtil.setInventory(player, inv);
+ bpUtil.setInventory(player, inv, id);
}
}
}
@@ -390,7 +390,7 @@ public static int itemStackRemoveAll(Player player, XMaterial xMat ) {
String id = null;
Inventory inv = BackpacksUtil.get().getBackpack(player, id);
removed += itemStackRemoveAll( xMat, inv );
- BackpacksUtil.get().setInventory( player, inv );
+ BackpacksUtil.get().setInventory( player, inv, id );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksListeners.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksListeners.java
index d380712b0..880241c65 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksListeners.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksListeners.java
@@ -81,17 +81,17 @@ private void saveBackpackEdited(InventoryCloseEvent e) {
id = title.substring(e.getPlayer().getName().length() + 13);
}
} catch (IndexOutOfBoundsException ignored){}
- if (id != null){
+// if (id != null){
if (BackpacksUtil.backpackEdited.contains(e.getPlayer().getName())){
BackpacksUtil.get().setInventory((Player) e.getPlayer(), e.getInventory(), id);
BackpacksUtil.get().removeFromEditedBackpack((Player) e.getPlayer());
}
- } else {
- if (BackpacksUtil.backpackEdited.contains(e.getPlayer().getName())) {
- BackpacksUtil.get().setInventory((Player) e.getPlayer(), e.getInventory());
- BackpacksUtil.get().removeFromEditedBackpack((Player) e.getPlayer());
- }
- }
+// } else {
+// if (BackpacksUtil.backpackEdited.contains(e.getPlayer().getName())) {
+// BackpacksUtil.get().setInventory((Player) e.getPlayer(), e.getInventory(), null);
+// BackpacksUtil.get().removeFromEditedBackpack((Player) e.getPlayer());
+// }
+// }
}
}
@@ -107,15 +107,17 @@ private void backpackEditEvent(InventoryClickEvent e) {
id = title.substring(e.getWhoClicked().getName().length() + 13);
}
} catch (IndexOutOfBoundsException ignored){}
- if (id != null){
- if (title.equalsIgnoreCase(e.getWhoClicked().getName() + " -> Backpack-" + id)){
+ String backpackId = id == null ?
+ "" : "-" + id;
+// if (id != null){
+ if (title.equalsIgnoreCase(e.getWhoClicked().getName() + " -> Backpack" + backpackId)){
BackpacksUtil.get().addToEditedBackpack((Player) e.getWhoClicked());
}
- } else {
- if (title != null && title.equalsIgnoreCase(e.getWhoClicked().getName() + " -> Backpack")) {
- BackpacksUtil.get().addToEditedBackpack((Player) e.getWhoClicked());
- }
- }
+// } else {
+// if (title != null && title.equalsIgnoreCase(e.getWhoClicked().getName() + " -> Backpack")) {
+// BackpacksUtil.get().addToEditedBackpack((Player) e.getWhoClicked());
+// }
+// }
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
index f54c75827..619c25261 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/backpacks/BackpacksUtil.java
@@ -12,6 +12,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.Configuration;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@@ -120,17 +121,18 @@ public OfflinePlayer getBackpackOwnerOffline(String name){
return getOfflinePlayer(name);
}
- /**
- * Get Backpack owner OfflinePlayer by name and backpack ID.
- *
- * @param name - PlayerName
- * @param id - InventoryID
- *
- * @return OfflinePlayer
- * */
- public OfflinePlayer getBackpackOwnerOffline(String name, String id){
- return getOfflinePlayer(name, id);
- }
+ // The following is exactly the same as the function without the id....
+// /**
+// * Get Backpack owner OfflinePlayer by name and backpack ID.
+// *
+// * @param name - PlayerName
+// * @param id - InventoryID
+// *
+// * @return OfflinePlayer
+// * */
+// public OfflinePlayer getBackpackOwnerOffline(String name, String id){
+// return getOfflinePlayer(name, id);
+// }
/**
* Get Backpack Player by name.
@@ -403,15 +405,15 @@ public Inventory getBackpack(Player p, Inventory inv){
return getBackpackCustom(p, inv);
}
- /**
- * Merge another inventory into the backpack inventory.
- *
- * @param p - player
- * @param inv - Inventory
- * */
- public void setInventory(Player p, Inventory inv){
- saveInventory(p, inv);
- }
+// /**
+// * Merge another inventory into the backpack inventory.
+// *
+// * @param p - player
+// * @param inv - Inventory
+// * */
+// public void setInventory(Player p, Inventory inv){
+// saveInventory(p, inv, null);
+// }
/**
* Merge another inventory into the backpack inventory by ID.
@@ -424,29 +426,29 @@ public void setInventory(Player p, Inventory inv, String id){
saveInventory(p, inv, id);
}
- /**
- * Add an item to the backpack inventory
- * NOT TESTED!
- *
- * RECOMMENDED WAY:
- * If you need to modify the inventory you can do it just by using BackPacksUtil getInventory(player),
- * modify your inventory as you'd usually with spigot inventories,
- * and then use BackPacksUtil setInventory(player, inventory) is recommended.
- *
- * EXAMPLE for adding item:
- * Inventory inv = BackPacksUtil.getInventory(p);
- * ItemStack item = new ItemStack(Material.COAL_ORE, 1);
- * inv.addItem(item);
- * BackPacksUtil.setInventory(inv);
- *
- * @param p - player
- * @param item - itemstack
- *
- * @return HashMap with items that didn't fit.
- * */
- public HashMap addItem(Player p, ItemStack item){
- return addItemToBackpack(p, item);
- }
+// /**
+// * Add an item to the backpack inventory
+// * NOT TESTED!
+// *
+// * RECOMMENDED WAY:
+// * If you need to modify the inventory you can do it just by using BackPacksUtil getInventory(player),
+// * modify your inventory as you'd usually with spigot inventories,
+// * and then use BackPacksUtil setInventory(player, inventory) is recommended.
+// *
+// * EXAMPLE for adding item:
+// * Inventory inv = BackPacksUtil.getInventory(p);
+// * ItemStack item = new ItemStack(Material.COAL_ORE, 1);
+// * inv.addItem(item);
+// * BackPacksUtil.setInventory(inv);
+// *
+// * @param p - player
+// * @param item - itemstack
+// *
+// * @return HashMap with items that didn't fit.
+// * */
+// public HashMap addItem(Player p, ItemStack item){
+// return addItemToBackpack(p, item, null);
+// }
/**
* Add an item to the backpack inventory
@@ -473,29 +475,29 @@ public HashMap addItem(Player p, ItemStack item, String id){
return addItemToBackpack(p, item, id);
}
- /**
- * Remove item from backpack
- * NOT TESTED!
- *
- * RECOMMENDED WAY:
- * If you need to modify the inventory you can do it just by using BackPacksUtil getInventory(player),
- * modify your inventory as you'd usually with spigot inventories,
- * and then use BackPacksUtil setInventory(player, inventory) is recommended.
- *
- * EXAMPLE for removing item:
- * Inventory inv = BackPacksUtil.getInventory(p);
- * ItemStack item = new ItemStack(Material.COAL_ORE, 1);
- * inv.removeItem(item);
- * BackPacksUtil.setInventory(inv);
- *
- * @param p - player
- * @param item - itemstack
- *
- * @return HashMap with items that couldn't be removed.
- * */
- public HashMap removeItem(Player p, ItemStack item){
- return removeItemFromBackpack(p, item);
- }
+// /**
+// * Remove item from backpack
+// * NOT TESTED!
+// *
+// * RECOMMENDED WAY:
+// * If you need to modify the inventory you can do it just by using BackPacksUtil getInventory(player),
+// * modify your inventory as you'd usually with spigot inventories,
+// * and then use BackPacksUtil setInventory(player, inventory) is recommended.
+// *
+// * EXAMPLE for removing item:
+// * Inventory inv = BackPacksUtil.getInventory(p);
+// * ItemStack item = new ItemStack(Material.COAL_ORE, 1);
+// * inv.removeItem(item);
+// * BackPacksUtil.setInventory(inv);
+// *
+// * @param p - player
+// * @param item - itemstack
+// *
+// * @return HashMap with items that couldn't be removed.
+// * */
+// public HashMap removeItem(Player p, ItemStack item){
+// return removeItemFromBackpack(p, item, null);
+// }
/**
* Remove item from backpack
@@ -1117,60 +1119,60 @@ private Inventory getBackpackCustom(Player p, Inventory inv) {
return inv;
}
- private void saveInventory(Player p, Inventory inv) {
- updateCachedBackpack();
-
- // Set dimensions if null or error.
- boolean needToSetNewDimensions = checkDimensionError(p, null);
- boolean needToSetNewOwner = checkBackpackOwnerMissing(p);
- boolean needToSetNewOwnerID = checkBackpackOwnerIDMissing(p);
-
- if (inv.getContents() != null){
-
- int backpackSize = getBackpackSize(p, null);
- int slot = 0;
-
- try {
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items", null);
- backpacksDataConfig.save(backpacksFile);
- } catch (IOException ex){
- ex.printStackTrace();
- return;
- }
-
- updateCachedBackpack();
-
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items.Size", backpackSize);
-
- for (ItemStack item : inv.getContents()){
- if (item != null){
-
- backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items." + slot + ".ITEMSTACK", item);
-
- slot++;
- }
- }
-
- oldDataVersionUpdater(p, null, false, true, true);
-
- try {
- backpacksDataConfig.save(backpacksFile);
- } catch (IOException ex){
- ex.printStackTrace();
- }
- } else {
- // If it's null just delete the whole stored inventory.
- oldDataVersionUpdater(p, null, needToSetNewDimensions, needToSetNewOwner, needToSetNewOwnerID);
- try {
- backpacksDataConfig.set("Inventories." + p.getUniqueId().toString() + ".Items", null);
- backpacksDataConfig.save(backpacksFile);
- } catch (IOException ex){
- ex.printStackTrace();
- }
- }
-
- updateCachedBackpack();
- }
+// private void saveInventory(Player p, Inventory inv) {
+// updateCachedBackpack();
+//
+// // Set dimensions if null or error.
+// boolean needToSetNewDimensions = checkDimensionError(p, null);
+// boolean needToSetNewOwner = checkBackpackOwnerMissing(p);
+// boolean needToSetNewOwnerID = checkBackpackOwnerIDMissing(p);
+//
+// if (inv.getContents() != null){
+//
+// int backpackSize = getBackpackSize(p, null);
+// int slot = 0;
+//
+// try {
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items", null);
+// backpacksDataConfig.save(backpacksFile);
+// } catch (IOException ex){
+// ex.printStackTrace();
+// return;
+// }
+//
+// updateCachedBackpack();
+//
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items.Size", backpackSize);
+//
+// for (ItemStack item : inv.getContents()){
+// if (item != null){
+//
+// backpacksDataConfig.set("Inventories." + p.getUniqueId() + ".Items." + slot + ".ITEMSTACK", item);
+//
+// slot++;
+// }
+// }
+//
+// oldDataVersionUpdater(p, null, false, true, true);
+//
+// try {
+// backpacksDataConfig.save(backpacksFile);
+// } catch (IOException ex){
+// ex.printStackTrace();
+// }
+// } else {
+// // If it's null just delete the whole stored inventory.
+// oldDataVersionUpdater(p, null, needToSetNewDimensions, needToSetNewOwner, needToSetNewOwnerID);
+// try {
+// backpacksDataConfig.set("Inventories." + p.getUniqueId().toString() + ".Items", null);
+// backpacksDataConfig.save(backpacksFile);
+// } catch (IOException ex){
+// ex.printStackTrace();
+// }
+// }
+//
+// updateCachedBackpack();
+// }
private void saveInventory(Player p, Inventory inv, String id) {
String backpackId = id == null ?
@@ -1260,13 +1262,13 @@ private void oldDataVersionUpdater(Player p, String id, boolean needToSetNewDime
}
}
- private HashMap addItemToBackpack(Player p, ItemStack item) {
- String id = null;
- Inventory inv = getBackpack(p, id);
- HashMap overflow = inv.addItem(item);
- setInventory(p, inv);
- return overflow;
- }
+// private HashMap addItemToBackpack(Player p, ItemStack item) {
+// String id = null;
+// Inventory inv = getBackpack(p, id);
+// HashMap overflow = inv.addItem(item);
+// setInventory(p, inv);
+// return overflow;
+// }
private HashMap addItemToBackpack(Player p, ItemStack item, String id) {
Inventory inv = getBackpack(p, id);
@@ -1275,13 +1277,13 @@ private HashMap addItemToBackpack(Player p, ItemStack item,
return overflow;
}
- private HashMap removeItemFromBackpack(Player p, ItemStack item) {
- String id = null;
- Inventory inv = getBackpack(p, id );
- HashMap underflow = inv.removeItem(item);
- setInventory(p, inv);
- return underflow;
- }
+// private HashMap removeItemFromBackpack(Player p, ItemStack item) {
+// String id = null;
+// Inventory inv = getBackpack(p, id );
+// HashMap underflow = inv.removeItem(item);
+// setInventory(p, inv);
+// return underflow;
+// }
private HashMap removeItemFromBackpack(Player p, ItemStack item, String id) {
Inventory inv = getBackpack(p, id);
@@ -1440,28 +1442,33 @@ private boolean checkBackpackOwnerIDMissing(Player p) {
// return backpacksDataConfig.getString("Inventories." + p.getUniqueId() + ".UniqueID") == null;
// }
- private OfflinePlayer getOfflinePlayer(String name) {
- if (name != null) {
- updateCachedBackpack();
- if (backpacksDataConfig.getConfigurationSection("Inventories") != null) {
- for (String uniqueID : backpacksDataConfig.getConfigurationSection("Inventories").getKeys(false)) {
- if (backpacksDataConfig.getString("Inventories." + uniqueID + ".PlayerName").equalsIgnoreCase(name) && backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID") != null) {
- return Bukkit.getOfflinePlayer(UUID.fromString(backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID")));
- }
- }
- }
- }
- return null;
- }
+// private OfflinePlayer getOfflinePlayer(String name) {
+// if (name != null) {
+// updateCachedBackpack();
+// if (backpacksDataConfig.getConfigurationSection("Inventories") != null) {
+// for (String uniqueID : backpacksDataConfig.getConfigurationSection("Inventories").getKeys(false)) {
+// if (backpacksDataConfig.getString("Inventories." + uniqueID + ".PlayerName").equalsIgnoreCase(name) && backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID") != null) {
+// return Bukkit.getOfflinePlayer(UUID.fromString(backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID")));
+// }
+// }
+// }
+// }
+// return null;
+// }
- private OfflinePlayer getOfflinePlayer(String name, String id) {
+ // what the hell? two functions with different parms but the damn exact same code????
+// private OfflinePlayer getOfflinePlayer(String name, String id) {
+ private OfflinePlayer getOfflinePlayer(String name) {
if (name != null) {
updateCachedBackpack();
- if (backpacksDataConfig.getConfigurationSection("Inventories") != null) {
- for (String uniqueID : backpacksDataConfig.getConfigurationSection("Inventories").getKeys(false)) {
- if (backpacksDataConfig.getString("Inventories." + uniqueID + ".PlayerName") != null && backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID") != null){
- if (backpacksDataConfig.getString("Inventories." + uniqueID + ".PlayerName").equalsIgnoreCase(name)){
- return Bukkit.getOfflinePlayer(UUID.fromString(backpacksDataConfig.getString("Inventories." + uniqueID + ".UniqueID")));
+ ConfigurationSection inventories = backpacksDataConfig.getConfigurationSection("Inventories");
+ if (inventories != null) {
+ for (String uniqueID : inventories.getKeys(false)) {
+ String playerName = inventories.getString(uniqueID + ".PlayerName");
+ String uuid = inventories.getString(uniqueID + ".UniqueID");
+ if (playerName != null && uuid != null){
+ if (playerName.equalsIgnoreCase(name)){
+ return Bukkit.getOfflinePlayer(UUID.fromString(uuid));
}
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
index 17485d1f0..4d07b0d54 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotBackpackCommands.java
@@ -25,7 +25,8 @@ public class PrisonSpigotBackpackCommands extends PrisonSpigotBaseCommands {
@Command(identifier = "backpack", description = "Backpacks", onlyPlayers = false)
private void backpackMainCommand(CommandSender sender,
- @Arg(name = "ID", def = "null", description = "Leave empty if you want to open your main backpack, add an ID if you've more than one.") String id){
+ @Arg(name = "ID", def = "null",
+ description = "Leave empty if you want to open your main backpack, add an ID if you've more than one.") String id){
if (sender.hasPermission("prison.admin") || sender.isOp()){
String registeredCmd = Prison.get().getCommandHandler().findRegisteredCommand("backpack help");
@@ -96,7 +97,7 @@ private void deleteBackpackCommand(CommandSender sender,
if (isOnlinePlayer) {
success = BackpacksUtil.get().resetBackpack(Bukkit.getPlayerExact(name), id);
} else {
- success = BackpacksUtil.get().resetBackpack(BackpacksUtil.get().getBackpackOwnerOffline(name, id), id);
+ success = BackpacksUtil.get().resetBackpack(BackpacksUtil.get().getBackpackOwnerOffline(name), id);
}
}
if (success) {
@@ -108,9 +109,9 @@ private void deleteBackpackCommand(CommandSender sender,
@Command(identifier = "backpack set size", description = "Resize a player's backpack.", permissions = "prison.admin", onlyPlayers = false)
private void resizeBackpackCommand(CommandSender sender,
- @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
- @Arg(name = "Backpack size", description = "Backpack size multiple of 9", def = "9") String size,
- @Arg(name = "id", description = "The backpack ID optional", def = "null") String id){
+ @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
+ @Arg(name = "Backpack size", description = "Backpack size multiple of 9", def = "9") String size,
+ @Arg(name = "id", description = "The backpack ID optional", def = "null") String id){
if (name.equalsIgnoreCase("null")){
Output.get().sendWarn(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_backpack_missing_playername)));
@@ -149,7 +150,7 @@ private void resizeBackpackCommand(CommandSender sender,
} else {
- BackpacksUtil.get().setBackpackSize(BackpacksUtil.get().getBackpackOwnerOffline(name, id), sizeInt, id);
+ BackpacksUtil.get().setBackpackSize(BackpacksUtil.get().getBackpackOwnerOffline(name), sizeInt, id);
}
}
@@ -157,15 +158,17 @@ private void resizeBackpackCommand(CommandSender sender,
Output.get().sendInfo(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_backpack_resize_success)));
}
- @Command(identifier = "backpack limit", permissions = "prison.admin", description = "Backpacks limit for player, to use this multiple backpacks must be enabled from the backpacks config or it won't have effect.", onlyPlayers = false)
+ @Command(identifier = "backpack limit", permissions = "prison.admin",
+ description = "Backpacks limit for player, to use this multiple backpacks must be enabled from the backpacks config or it won't have effect.", onlyPlayers = false)
private void backpackLimitMainCommand(CommandSender sender){
sender.dispatchCommand("backpack limit help");
}
- @Command(identifier = "backpack limit set", permissions = "prison.admin", description = "Set backpacks limit of a player, to use this multiple backpacks must be enabled or it won't have effect.", onlyPlayers = false)
+ @Command(identifier = "backpack limit set",
+ permissions = "prison.admin", description = "Set backpacks limit of a player, to use this multiple backpacks must be enabled or it won't have effect.", onlyPlayers = false)
private void setBackpackLimitCommand(CommandSender sender,
- @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
- @Arg(name = "Limit", description = "The Backpacks limit that a player can own", def = "null") String limit) {
+ @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
+ @Arg(name = "Limit", description = "The Backpacks limit that a player can own", def = "null") String limit) {
if (name.equalsIgnoreCase("null") || limit.equalsIgnoreCase("null")){
Output.get().sendWarn(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_command_wrong_format)));
@@ -189,10 +192,12 @@ private void setBackpackLimitCommand(CommandSender sender,
Output.get().sendInfo(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_backpack_limit_edit_success)));
}
- @Command(identifier = "backpack limit add", permissions = "prison.admin", description = "Increment backpacks limit of a player, multiple backpacks must be enabled or this won't take effect.", onlyPlayers = false)
+ @Command(identifier = "backpack limit add",
+ permissions = "prison.admin",
+ description = "Increment backpacks limit of a player, multiple backpacks must be enabled or this won't take effect.", onlyPlayers = false)
private void addBackpackLimitCommand(CommandSender sender,
- @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
- @Arg(name = "Limit", description = "The Backpacks increment value", def = "null") String limit) {
+ @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
+ @Arg(name = "Limit", description = "The Backpacks increment value", def = "null") String limit) {
if (name.equalsIgnoreCase("null") || limit.equalsIgnoreCase("null")){
Output.get().sendWarn(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_command_wrong_format)));
@@ -218,10 +223,11 @@ private void addBackpackLimitCommand(CommandSender sender,
Output.get().sendInfo(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_backpack_limit_edit_success)));
}
- @Command(identifier = "backpack limit decrement", permissions = "prison.admin", description = "Decrement backpacks limit of a player, to use this multiple backpacks must be enabled or it won't have effect.", onlyPlayers = false)
+ @Command(identifier = "backpack limit decrement", permissions = "prison.admin",
+ description = "Decrement backpacks limit of a player, to use this multiple backpacks must be enabled or it won't have effect.", onlyPlayers = false)
private void decrementBackpackLimitCommand(CommandSender sender,
- @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
- @Arg(name = "Value", description = "The Backpacks decrement value", def = "null") String limit) {
+ @Arg(name = "Owner", description = "The backpack owner name", def = "null") String name,
+ @Arg(name = "Value", description = "The Backpacks decrement value", def = "null") String limit) {
if (name.equalsIgnoreCase("null") || limit.equalsIgnoreCase("null")){
Output.get().sendWarn(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_command_wrong_format)));
@@ -257,7 +263,8 @@ private void decrementBackpackLimitCommand(CommandSender sender,
Output.get().sendInfo(sender, SpigotPrison.format(messages.getString(MessagesConfig.StringID.spigot_message_backpack_limit_edit_success)));
}
- @Command(identifier = "backpack admin", description = "Open backpack admin GUI", permissions = "prison.admin", onlyPlayers = true)
+ @Command(identifier = "backpack admin", description = "Open backpack admin GUI",
+ permissions = "prison.admin", onlyPlayers = true)
private void openBackpackAdminGUI(CommandSender sender){
Player p = getSpigotPlayer(sender);
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
index 8d01187cb..451737ac2 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
@@ -1462,7 +1462,7 @@ public void removeSellableItems(Player p){
}
} else {
String id = null;
- backpacksUtil.setInventory(p, removeSellableItems(p, backpacksUtil.getBackpack(p, id)));
+ backpacksUtil.setInventory(p, removeSellableItems(p, backpacksUtil.getBackpack(p, id)), id);
}
}
From 622bc3c4cdc171eaffeba7de17fce2d107e6e177 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 15 Sep 2022 07:09:39 -0400
Subject: [PATCH 021/129] Removed support for MVdWPlaceholder plugin. It
generates way too many entries in the log, and there is zero support for it
from the providers. It's also unneeded since PlaceholderAPI works perfectly
fine with it, so it's 100% pointless.
---
docs/changelog_v3.3.x.md | 7 +-
.../mcprison/prison/spigot/SpigotPrison.java | 9 +-
.../MVdWPlaceholderIntegration.java | 371 +++++++++---------
.../MVdWPlaceholderIntegrationWrapper.java | 26 +-
4 files changed, 196 insertions(+), 217 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index be5a769b2..2ceaae097 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,12 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-09-14
+# 3.3.0-alpha.13b 2022-09-15
+
+
+* **Removed support for MVdWPlaceholder plugin.**
+It generates way too many entries in the log, and there is zero support for it from the providers.
+It's also unneeded since PlaceholderAPI works perfectly fine with it, so it's 100% pointless.
* **More refactoring of the old backpacks to get rid of bad code to make it easier to integrate in to a newer backpack framework.**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java
index 0500e4926..42a15532d 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java
@@ -86,7 +86,6 @@
import tech.mcprison.prison.spigot.permissions.LuckPermissions;
import tech.mcprison.prison.spigot.permissions.LuckPerms5;
import tech.mcprison.prison.spigot.permissions.VaultPermissions;
-import tech.mcprison.prison.spigot.placeholder.MVdWPlaceholderIntegration;
import tech.mcprison.prison.spigot.placeholder.PlaceHolderAPIIntegration;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
import tech.mcprison.prison.spigot.slime.SlimeBlockFunEventListener;
@@ -916,7 +915,7 @@ private void initIntegrations() {
registerIntegration(new LuckPerms5());
registerIntegration(new LuckPermissions());
- registerIntegration(new MVdWPlaceholderIntegration());
+// registerIntegration(new MVdWPlaceholderIntegration());
registerIntegration(new PlaceHolderAPIIntegration());
registerIntegration(new CustomItems());
@@ -951,13 +950,13 @@ public boolean isPluginEnabled( String pluginName ) {
*/
public void reloadIntegrationsPlaceholders() {
- MVdWPlaceholderIntegration ph1 = new MVdWPlaceholderIntegration();
+// MVdWPlaceholderIntegration ph1 = new MVdWPlaceholderIntegration();
PlaceHolderAPIIntegration ph2 = new PlaceHolderAPIIntegration();
- registerIntegration(ph1);
+// registerIntegration(ph1);
registerIntegration(ph2);
- ph1.deferredInitialization();
+// ph1.deferredInitialization();
ph2.deferredInitialization();
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/placeholder/MVdWPlaceholderIntegration.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/placeholder/MVdWPlaceholderIntegration.java
index e479e9630..44c020524 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/placeholder/MVdWPlaceholderIntegration.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/placeholder/MVdWPlaceholderIntegration.java
@@ -1,23 +1,5 @@
package tech.mcprison.prison.spigot.placeholder;
-import java.util.List;
-import java.util.function.Function;
-
-import org.bukkit.Bukkit;
-
-import tech.mcprison.prison.PrisonAPI;
-import tech.mcprison.prison.internal.Player;
-import tech.mcprison.prison.mines.PrisonMines;
-import tech.mcprison.prison.mines.managers.MineManager;
-import tech.mcprison.prison.output.Output;
-import tech.mcprison.prison.placeholders.PlaceHolderKey;
-import tech.mcprison.prison.placeholders.PlaceholderIdentifier;
-import tech.mcprison.prison.placeholders.PlaceholderIntegration;
-import tech.mcprison.prison.ranks.PrisonRanks;
-import tech.mcprison.prison.ranks.managers.PlayerManager;
-import tech.mcprison.prison.ranks.managers.RankManager;
-import tech.mcprison.prison.util.Text;
-
/**
*
This hooks up the registration when the Prison plugin starts to run.
* The MVdWPlaceholderIntegrationWrapper sets up the registrations. It should
@@ -35,186 +17,187 @@
*
*/
public class MVdWPlaceholderIntegration
- extends PlaceholderIntegration {
+// extends PlaceholderIntegration
+ {
- private MVdWPlaceholderIntegrationWrapper placeholderWrapper;
+// private MVdWPlaceholderIntegrationWrapper placeholderWrapper;
+//
+// public MVdWPlaceholderIntegration() {
+// super( "MVdWPlaceholderAPI", "MVdWPlaceholderAPI" );
+// }
- public MVdWPlaceholderIntegration() {
- super( "MVdWPlaceholderAPI", "MVdWPlaceholderAPI" );
- }
+// @Override
+// public void integrate() {
+// if ( isRegistered()) {
+// try {
+// if ( Bukkit.getPluginManager().isPluginEnabled(getProviderName())) {
+//
+//
+// // The integration was written for MVdW v3.0.0, but if used with older versions
+// // it will fail.
+//
+// // This will fail if the version of mvdw is v2.x.x, which is what we want:
+// Class.forName("be.maximvdw.placeholderapi.PlaceholderAPI", false, getClass().getClassLoader());
+//
+// MVdWPlaceholderIntegrationWrapper wrap = new MVdWPlaceholderIntegrationWrapper(getProviderName());
+//
+// placeholderWrapper = wrap;
+//
+// PrisonAPI.getIntegrationManager().addDeferredInitialization( this );
+// }
+// }
+// catch ( NoClassDefFoundError e ) {
+// // ignore this exception since it means the plugin was not loaded
+// Output.get().logWarn( "Attempted to enable the MVdWPlaceholderIntegration but it failed to find the " +
+// "class 'be.maximvdw.placeholderapi.PlaceholderAPI'. This could happen when using " +
+// "MVdWPlaceholderApi v2.x.x. Prison ONLY support MVdW v3.x.x. " +
+// "&c****&7 Try using PlaceholderAPI (papi) instead. &c****" );
+// }
+// catch ( IllegalStateException e ) {
+// // ignore ... plugin is not loaded
+// }
+// catch ( Exception e ) {
+// e.printStackTrace();
+// }
+// }
+// }
- @Override
- public void integrate() {
- if ( isRegistered()) {
- try {
- if ( Bukkit.getPluginManager().isPluginEnabled(getProviderName())) {
-
-
- // The integration was written for MVdW v3.0.0, but if used with older versions
- // it will fail.
-
- // This will fail if the version of mvdw is v2.x.x, which is what we want:
- Class.forName("be.maximvdw.placeholderapi.PlaceholderAPI", false, getClass().getClassLoader());
-
- MVdWPlaceholderIntegrationWrapper wrap = new MVdWPlaceholderIntegrationWrapper(getProviderName());
-
- placeholderWrapper = wrap;
-
- PrisonAPI.getIntegrationManager().addDeferredInitialization( this );
- }
- }
- catch ( NoClassDefFoundError e ) {
- // ignore this exception since it means the plugin was not loaded
- Output.get().logWarn( "Attempted to enable the MVdWPlaceholderIntegration but it failed to find the " +
- "class 'be.maximvdw.placeholderapi.PlaceholderAPI'. This could happen when using " +
- "MVdWPlaceholderApi v2.x.x. Prison ONLY support MVdW v3.x.x. " +
- "&c****&7 Try using PlaceholderAPI (papi) instead. &c****" );
- }
- catch ( IllegalStateException e ) {
- // ignore ... plugin is not loaded
- }
- catch ( Exception e ) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- *
Register both the player and mines placeholders with the MVdW plugin.
- *
- */
- @Override
- public void deferredInitialization()
- {
- boolean registered = false;
- if ( PrisonRanks.getInstance() != null && PrisonRanks.getInstance().isEnabled() ) {
-
- PlayerManager pm = PrisonRanks.getInstance().getPlayerManager();
- if ( pm != null ) {
- List placeholderPlayerKeys = pm.getTranslatedPlaceHolderKeys();
-
- for ( PlaceHolderKey placeHolderKey : placeholderPlayerKeys ) {
- if ( !placeHolderKey.getPlaceholder().isSuppressed() ) {
-
-
- registerPlaceholder(placeHolderKey.getKey(),
- player -> {
-
- PlaceholderIdentifier identifier = new PlaceholderIdentifier( placeHolderKey.getPlaceholder().name() );
- identifier.setPlayer( player.getUUID(), player.getName() );
-
- if ( identifier.checkPlaceholderKey(placeHolderKey) ) {
-
- pm.getTranslatePlayerPlaceHolder( identifier );
- }
-
-
- return Text.translateAmpColorCodes( identifier.getText() );
- });
- if ( !registered ) {
- registered = true;
- }
- }
- }
- }
-
- RankManager rm = PrisonRanks.getInstance().getRankManager();
- if ( rm != null ) {
- List placeholderPlayerKeys = rm.getTranslatedPlaceHolderKeys();
-
- for ( PlaceHolderKey placeHolderKey : placeholderPlayerKeys ) {
- if ( !placeHolderKey.getPlaceholder().isSuppressed() ) {
-
-
- registerPlaceholder(placeHolderKey.getKey(),
- player -> {
-
- PlaceholderIdentifier identifier = new PlaceholderIdentifier( placeHolderKey.getPlaceholder().name() );
- identifier.setPlayer( player.getUUID(), player.getName() );
-
- if ( identifier.checkPlaceholderKey(placeHolderKey) ) {
-
- rm.getTranslateRanksPlaceHolder( identifier );
- }
-
-
- return Text.translateAmpColorCodes( identifier.getText() );
- });
- if ( !registered ) {
- registered = true;
- }
- }
- }
- }
- }
-
-
- if ( PrisonMines.getInstance() != null && PrisonMines.getInstance().isEnabled() ) {
- MineManager mm = PrisonMines.getInstance().getMineManager();
- if ( mm != null ) {
- List placeholderMinesKeys = mm.getTranslatedPlaceHolderKeys();
-
- for ( PlaceHolderKey placeHolderKey : placeholderMinesKeys ) {
- if ( !placeHolderKey.getPlaceholder().isSuppressed() ) {
-
- registerPlaceholder(placeHolderKey.getKey(),
- player -> {
-
- PlaceholderIdentifier identifier = new PlaceholderIdentifier( placeHolderKey.getPlaceholder().name() );
- identifier.setPlayer( player.getUUID(), player.getName() );
-
- if ( identifier.checkPlaceholderKey(placeHolderKey) ) {
-
- mm.getTranslateMinesPlaceholder( identifier );
- }
-
- return Text.translateAmpColorCodes( identifier.getText() );
- } );
- if ( !registered ) {
- registered = true;
- }
- }
- }
- }
- }
-
-// if ( registered ) {
-// Output.get().logWarn( "Prison registered all placeholders with MVdWPlaceholderAPI, " +
-// "but unfortunately MVdWPlaceholderAPI does not support dynamic placeholders " +
-// "that are available for customizations within prison. Please try adding " +
-// "Vault and PlaceholderAPI (papi) to your setup, if they do not already exist, " +
-// "to enable these features.");
+// /**
+// *
Register both the player and mines placeholders with the MVdW plugin.
+// *
Use of this method is discouraged. Implementations are recommended to
+ *
Translates color codes (a-f) (A-F) (0-9), prefixed by an ampersand, into Minecraft-readable
+ * color codes.
+ *
+ *
+ *
Use of this method is discouraged. Implementations are recommended to
* translate color codes using their native internal's APIs. This assumes that the server mod will
* accept vanilla Minecraft color codes, although implementations such as Sponge do not do this.
* However, because there are some practical uses for a method like this, it exists in a
* non-deprecated but discouraged state.
+ *
This function will check for the largest backpack size permitted
+ * for a player by using the perm `prison.backpack.size.`. If a perm
+ * exists, then it will set a max size for the player, which will set the
+ * max size for the backpack if the backpack size is greater than the perm.
+ * If a player does not have this perm, then the backpack size will not be
+ * limited.
+ *
+ *
+ * @param p
+ * @param backPackSize
+ * @return
+ */
private int getBackpackPermSize(Player p, int backPackSize) {
SpigotPlayer sPlayer = new SpigotPlayer(p);
List perms = sPlayer.getPermissions("prison.backpack.size.");
@@ -1042,38 +1079,82 @@ private int getBackpackPermSize(Player p, int backPackSize) {
// return inv;
// }
+ /**
+ *
This function returns prison based objects.
+ *
+ *
+ * @param player
+ * @param id
+ * @return
+ */
+ public List getPrisonBackpackContents( UUID playerUuid, String id ) {
+ List contents = new ArrayList<>();
+
+ String backpackId = id == null ?
+ "" : "-" + id;
+
+ updateCachedBackpack();
+
+ int size = getBackpackSize( playerUuid, id);
+
+ // Get the Items config section
+ Set slots;
+ try {
+ slots = backpacksDataConfig.getConfigurationSection(
+ "Inventories." + playerUuid + ".Items" + backpackId).getKeys(false);
+ } catch (NullPointerException ex){
+ return contents;
+ }
+
+ if (slots.size() != 0) {
+ for (String slot : slots) {
+ ItemStack finalItem = backpacksDataConfig.getItemStack(
+ "Inventories." + playerUuid + ".Items" + backpackId + "." + slot + ".ITEMSTACK");
+ if (finalItem != null) {
+ int slotNumber = Integer.parseInt(slot);
+ if (size > slotNumber) {
+
+ contents.add( new SpigotItemStack( finalItem ));
+ }
+ }
+ }
+ }
+
+ return contents;
+ }
+
private Inventory getBackpackOwn(Player p, String id) {
String backpackId = id == null ?
"" : "-" + id;
- updateCachedBackpack();
-
- int size = getBackpackSize(p, id);
-
- Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack" + backpackId));
-
- // Get the Items config section
- Set slots;
- try {
- slots = backpacksDataConfig.getConfigurationSection(
- "Inventories." + p.getUniqueId() + ".Items" + backpackId).getKeys(false);
- } catch (NullPointerException ex){
- return inv;
- }
- if (slots.size() != 0) {
- for (String slot : slots) {
- ItemStack finalItem = backpacksDataConfig.getItemStack(
- "Inventories." + p.getUniqueId() + ".Items" + backpackId + "." + slot + ".ITEMSTACK");
- if (finalItem != null) {
- int slotNumber = Integer.parseInt(slot);
- if (size > slotNumber) {
- inv.setItem(slotNumber, finalItem);
- }
- }
- }
- }
-
- return inv;
+ updateCachedBackpack();
+
+ int size = getBackpackSize(p, id);
+
+ Inventory inv = Bukkit.createInventory(p, size, SpigotPrison.format("&3" + p.getName() + " -> Backpack" + backpackId));
+
+ // Get the Items config section
+ Set slots;
+ try {
+ slots = backpacksDataConfig.getConfigurationSection(
+ "Inventories." + p.getUniqueId() + ".Items" + backpackId).getKeys(false);
+ } catch (NullPointerException ex){
+ return inv;
+ }
+ if (slots.size() != 0) {
+ for (String slot : slots) {
+ ItemStack finalItem = backpacksDataConfig.getItemStack(
+ "Inventories." + p.getUniqueId() + ".Items" + backpackId + "." + slot + ".ITEMSTACK");
+ if (finalItem != null) {
+ int slotNumber = Integer.parseInt(slot);
+ if (size > slotNumber) {
+ inv.setItem(slotNumber, finalItem);
+ }
+ }
+ }
+ }
+
+ return inv;
}
// private void openBackpackMethod(Player p) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotOfflinePlayer.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotOfflinePlayer.java
index ac9f715c6..758ca41a6 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotOfflinePlayer.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotOfflinePlayer.java
@@ -18,12 +18,16 @@
import tech.mcprison.prison.internal.inventory.Inventory;
import tech.mcprison.prison.internal.scoreboard.Scoreboard;
import tech.mcprison.prison.output.Output;
+import tech.mcprison.prison.ranks.PrisonRanks;
+import tech.mcprison.prison.ranks.data.RankPlayer;
import tech.mcprison.prison.util.Gamemode;
import tech.mcprison.prison.util.Location;
public class SpigotOfflinePlayer
implements OfflineMcPlayer {
+ private RankPlayer rankPlayer;
+
private OfflinePlayer offlinePlayer;
public SpigotOfflinePlayer(OfflinePlayer offlinePlayer) {
@@ -324,6 +328,13 @@ public void setTitle( String title, String subtitle, int fadeIn, int stay, int f
public void setActionBar( String actionBar ) {
}
+ public RankPlayer getRankPlayer() {
+ if ( rankPlayer == null ) {
+ rankPlayer = PrisonRanks.getInstance().getPlayerManager().getPlayer( this );
+ }
+ return rankPlayer;
+ }
+
@Override
public PlayerCache getPlayerCache() {
return PlayerCache.getInstance();
From e034af900fb6d7d42ce8432e81a90804f6388642 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 15 Oct 2022 15:13:16 -0400
Subject: [PATCH 029/129] If inspection of other plugin's jars fail, then just
ignore this issue and continue on processing.
---
docs/changelog_v3.3.x.md | 5 ++++-
.../prison/util/PrisonJarReporter.java | 18 ++++++++++++------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index ff3cc8a6c..e724fc204 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-09-27
+# 3.3.0-alpha.13b 2022-10-15
+
+
+* **If inspection of other plugin's jars fail, then just ignore this issue and continue on processing.**
* **New prison backpacks: More work on getting them setup for testing the BackpackCache.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
index 374d19779..7f7b71038 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
@@ -207,14 +207,20 @@ public void scanForJars() {
}
}
- catch ( ZipException e )
+ catch ( Exception e )
{
- e.printStackTrace();
- }
- catch ( IOException e )
- {
- e.printStackTrace();
+ // Ignore all errors.
+ // These are not our plugins, so if there is a problem, then it really does not matter
+
}
+// catch ( ZipException e )
+// {
+// e.printStackTrace();
+// }
+// catch ( IOException e )
+// {
+// e.printStackTrace();
+// }
}
From e2eaabb27bdcf4e198b4df13bfca66c9f5d5e10c Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 16 Oct 2022 15:24:01 -0400
Subject: [PATCH 030/129] Bug: Found a major bug in calculating a vector's
length since x should have been squared, but instead it was multiplied by y.
---
docs/changelog_v3.3.x.md | 6 +++++-
.../src/main/java/tech/mcprison/prison/util/Vector.java | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index e724fc204..3994fa8c0 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-10-15
+# 3.3.0-alpha.13b 2022-10-16
+
+
+* **Bug: Found a major bug in calculating a vector's length since x should have been squared, but instead it was multiplied by y.**
+The use of vectors is limited within Prison, but when used, this could cause issues.
* **If inspection of other plugin's jars fail, then just ignore this issue and continue on processing.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/Vector.java b/prison-core/src/main/java/tech/mcprison/prison/util/Vector.java
index 6c404219c..46c93e2ee 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/Vector.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/Vector.java
@@ -236,7 +236,7 @@ public double length() {
* @return the magnitude
*/
public double lengthSquared() {
- return x * y + y * y + z * z;
+ return x * x + y * y + z * z;
}
/**
From 22f7ec57267e4802d888bc48953429b8add3a977 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 17 Oct 2022 12:10:30 -0400
Subject: [PATCH 031/129] Small updates to help prepare for the internal change
to how PrisonBlocks are structured.
---
docs/changelog_v3.3.x.md | 5 +-
docs/knownissues_v3.3.x.md | 30 ++++++++-
.../mcprison/prison/file/FileCollection.java | 6 +-
.../mcprison/prison/file/FileDatabase.java | 6 +-
.../tech/mcprison/prison/file/JsonFileIO.java | 21 +++++++
.../internal/block/PrisonBlockStatusData.java | 62 +++++++++----------
.../tech/mcprison/prison/util/Location.java | 8 +++
.../prison/util/PrisonJarReporter.java | 1 -
8 files changed, 101 insertions(+), 38 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 3994fa8c0..5d746e239 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-10-16
+# 3.3.0-alpha.13b 2022-10-17
+
+
+* **Small updates to help prepare for the internal change to how PrisonBlocks are structured.**
* **Bug: Found a major bug in calculating a vector's length since x should have been squared, but instead it was multiplied by y.**
diff --git a/docs/knownissues_v3.3.x.md b/docs/knownissues_v3.3.x.md
index 1ab2be496..8f43d3077 100644
--- a/docs/knownissues_v3.3.x.md
+++ b/docs/knownissues_v3.3.x.md
@@ -8,10 +8,34 @@
# TODO Items for v3.3.0-alpha.13
+- File save to new format - OmarG
+ - pre-req for turning off TP
+ - pre-req for custom mine shapes
+
+
+- Ability to turn of TP on mine resets. OmarG
+ - Maybe have a special value for spawn to indicate it should TP?
+ - Could still have a spawn point, but just not tp during resets.
+
+
+- custom mine shapes - Chain and Fiba1 and OmarG
+ - Have a new command to edit and save the mine's shapes
+ - edit would spawn red/yellow wool - remove blocks - save would only save the wool blocks.
+
+
+- fix gui ranks to remove italics from the rank names. This may be the gui ranks and/or the gui prestiges. - Bryton
+ Cannot reproduce - No italics are being added by prison.
+
+
+- DONE: Gui prestiges - option to remove the gui prestige button. Not sure if any of the options in the config.sys really supports that. - Bryton
+
+
+
- Prestige - needs improvements
- - Confirmation does not perform any prechecks to confirm if the player can even prestige
- - Confirmation does not reflect prestige settins. It always shows that rank and balance will be reset, even if that is disabled.
- - It's not clear how to confirm via chat
+ DONE: rewrote the prestige handling to exist in the ranks module. Everything is handled properly now. The GUI is passed the correct lore so no rankup logic is in the gui anymore. Prechecks are now enabled too.
+ - DONE: Confirmation does not perform any prechecks to confirm if the player can even prestige
+ - DONE: Confirmation does not reflect prestige settins. It always shows that rank and balance will be reset, even if that is disabled.
+ - DONE: It's not clear how to confirm via chat
- when testing the block breakage with the SHIFT-click with the mine wand, I also saw that it processed the same block twice. The first time looked as if the drop was being canceled, then the second time the event was being canceled. Or vice-a-versa. I don't remember setting it up both ways.
diff --git a/prison-core/src/main/java/tech/mcprison/prison/file/FileCollection.java b/prison-core/src/main/java/tech/mcprison/prison/file/FileCollection.java
index a94d97860..e1323e123 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/file/FileCollection.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/file/FileCollection.java
@@ -38,7 +38,11 @@ public String getName() {
return collDir.getName();
}
- /**
+ public File getCollDir() {
+ return collDir;
+ }
+
+ /**
*
Refresh is a function that will clear the databaseMap collection if it contains anything,
* then load all possible FileDatabase objects, ignoring those that been virtually deleted.
*
Refresh is a function that will clear the collectionMap collection if it contains anything,
* then load all possible FileCollection objects, ignoring those that been virtually deleted.
*
This constructs a player file named based upon the UUID followed
* by the player's name. This format is used so it's easier to identify
@@ -99,6 +110,16 @@ public void saveJsonFile( File file, FileIOData data )
}
}
+ public void saveJsonExposedFile( File file, FileIOData data )
+ {
+ if ( file != null && data != null )
+ {
+ String json = getGsonExposed().toJson( data );
+
+ saveFile( file, json );
+ }
+ }
+
/**
* This function will try to load the given file, of which the contents should be
* JSon. If it is successful then the resulting object will represent the file.
diff --git a/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java b/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
index d92a4def0..983f5a0ab 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
@@ -345,37 +345,37 @@ private boolean checkGravityAffects( String blockName )
switch ( blockName )
{
- case "sand":
- case "red_sand":
- case "gravel":
-
- case "white_concrete_powder":
- case "orange_concrete_powder":
- case "magenta_concrete_powder":
- case "light_blue_concrete_powder":
- case "yellow_concrete_powder":
- case "lime_concrete_powder":
- case "pink_concrete_powder":
- case "gray_concrete_powder":
- case "light_gray_concrete_powder":
- case "cyan_concrete_powder":
- case "purple_concrete_powder":
- case "blue_concrete_powder":
- case "brown_concrete_powder":
- case "green_concrete_powder":
- case "red_concrete_powder":
- case "black_concrete_powder":
-
- case "anvil":
- case "chipped_anvil":
- case "damaged_anvil":
-
- case "scaffolding":
- case "pointed_dripstone":
- case "dragon_egg":
- {
- results = true;
- }
+ case "sand":
+ case "red_sand":
+ case "gravel":
+
+ case "white_concrete_powder":
+ case "orange_concrete_powder":
+ case "magenta_concrete_powder":
+ case "light_blue_concrete_powder":
+ case "yellow_concrete_powder":
+ case "lime_concrete_powder":
+ case "pink_concrete_powder":
+ case "gray_concrete_powder":
+ case "light_gray_concrete_powder":
+ case "cyan_concrete_powder":
+ case "purple_concrete_powder":
+ case "blue_concrete_powder":
+ case "brown_concrete_powder":
+ case "green_concrete_powder":
+ case "red_concrete_powder":
+ case "black_concrete_powder":
+
+ case "anvil":
+ case "chipped_anvil":
+ case "damaged_anvil":
+
+ case "scaffolding":
+ case "pointed_dripstone":
+ case "dragon_egg":
+ {
+ results = true;
+ }
}
}
return results;
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/Location.java b/prison-core/src/main/java/tech/mcprison/prison/util/Location.java
index 19ffde5c3..2c2a83a20 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/Location.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/Location.java
@@ -148,6 +148,14 @@ public void setBlockAsync( PrisonBlock prisonBlock ) {
world.setBlockAsync( prisonBlock, this );
}
+ /**
+ *
The edge identifies if a block is along the edge, or corner, of a mine.
+ * It's these blocks that becomes the pink glass tracer blocks when
+ * when enabling the tracer on a mine.
+ *
+ *
+ * @return
+ */
public boolean isEdge() {
return isEdge;
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
index 7f7b71038..c59fc3c9c 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonJarReporter.java
@@ -14,7 +14,6 @@
import java.util.List;
import java.util.TreeMap;
import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import tech.mcprison.prison.Prison;
From cf5767bb9dd3c9c2f972b4be6ba3723af1e5803e Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 17 Oct 2022 12:15:39 -0400
Subject: [PATCH 032/129] v3.3.0-alpha.13c 2022-10-17
---
docs/changelog_v3.3.x.md | 6 +++++-
gradle.properties | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 5d746e239..67e9eb29f 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13b 2022-10-17
+# 3.3.0-alpha.13c 2022-10-17
+
+
+**3.3.0-alpha.13c 2022-10-17**
+NOTE: Changes to PrisonBlock structures have been stashed and are not included in this alpha.13c release.
* **Small updates to help prepare for the internal change to how PrisonBlocks are structured.**
diff --git a/gradle.properties b/gradle.properties
index c2c296f77..e8a461794 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,7 +3,7 @@
## # This is actually the "correct" place to define the version for the project.
## # Used within build.gradle with ${project.version}.
## # Can be overridden on the command line: gradle -Pversion=3.2.1-alpha.3
-version=3.3.0-alpha.13b
+version=3.3.0-alpha.13c
From 75a6965324de7432eed21f1d88c2743155bf1893 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Tue, 1 Nov 2022 12:43:58 -0400
Subject: [PATCH 033/129] Mine Bombs bug fix: Was using a function that was
incompatible with bukkit 1.8.8 and this fixes that issue. Using a prison
compatibility function to provide the compatibility. Added more information
on why mine bombs are not working when prison is in debug mode.
---
docs/changelog_v3.3.x.md | 7 ++++-
.../spigot/utils/PrisonBombListener.java | 30 ++++++++++++++-----
.../spigot/utils/PrisonUtilsMineBombs.java | 6 ++--
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 67e9eb29f..8434db28e 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,12 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13c 2022-10-17
+# 3.3.0-alpha.13c 2022-11-01
+
+
+* **Mine Bombs bug fix: Was using a function that was incompatible with bukkit 1.8.8 and this fixes that issue.**
+Using a prison compatibility function to provide the compatibility.
+Added more information on why mine bombs are not working when prison is in debug mode.
**3.3.0-alpha.13c 2022-10-17**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonBombListener.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonBombListener.java
index ed2dc5c3e..f0e88deff 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonBombListener.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonBombListener.java
@@ -8,7 +8,6 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.inventory.EquipmentSlot;
import de.tr7zw.nbtapi.NBTItem;
import tech.mcprison.prison.bombs.MineBombData;
@@ -17,6 +16,8 @@
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.spigot.block.OnBlockBreakMines;
import tech.mcprison.prison.spigot.block.SpigotBlock;
+import tech.mcprison.prison.spigot.compat.Compatibility.EquipmentSlot;
+import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.util.Location;
@@ -75,9 +76,10 @@ public void onInteract( PlayerInteractEvent event ) {
String bombName = nbtItem.getString( MineBombs.MINE_BOMBS_NBT_BOMB_KEY );
- if ( Output.get().isDebug() && nbtItem != null ) {
- Output.get().logInfo( "PrisonBombListener.onInteract ntb: %s :: %s",
- bombName, nbtItem.toString() );
+ if ( Output.get().isDebug() ) {
+ Output.get().logInfo( "PrisonBombListener.onInteract bombName: &7%s&r &3:: nbt: &r%s",
+ bombName,
+ (nbtItem == null ? "&a-no-nbt-" : nbtItem.toString()) );
}
Player player = event.getPlayer();
@@ -104,7 +106,10 @@ public void onInteract( PlayerInteractEvent event ) {
if ( bomb == null ) {
-
+ if ( Output.get().isDebug() ) {
+ Output.get().logInfo( "MineBombs: The bomb named '%s' cannot be mapped to a mine bomb.",
+ bombName );
+ }
return;
}
@@ -130,17 +135,28 @@ public void onInteract( PlayerInteractEvent event ) {
if ( mine == null ) {
// player is not in a mine, so do not allow them to trigger a mine bomb:
+ if ( Output.get().isDebug() ) {
+ Output.get().logInfo( "MineBombs: Cannot mine bombs use outside of mines." );
+ }
+
event.setCancelled( true );
return;
}
else if ( !mine.hasMiningAccess( sPlayer ) ) {
// Player does not have access to the mine, so don't allow them to trigger a mine bomb:
+ if ( Output.get().isDebug() ) {
+ Output.get().logInfo( "MineBombs: Player %s&r does not have access to Mine %s&r.",
+ sPlayer.getName(), mine.getName());
+ }
+
event.setCancelled( true );
return;
}
- EquipmentSlot hand = event.getHand();
+ // getHand() is not available with bukkit 1.8.8 so use the compatibility functions:
+ EquipmentSlot hand = SpigotCompatibility.getInstance().getHand(event);
+// EquipmentSlot hand = event.getHand();
// Output.get().logInfo( "### PrisonBombListener: PlayerInteractEvent 02 " );
if ( getPrisonUtilsMineBombs().setBombInHand( player, bomb, sBlock, hand ) ) {
@@ -154,8 +170,6 @@ else if ( !mine.hasMiningAccess( sPlayer ) ) {
-
-
}
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
index 60f4d32eb..aaa4ddad8 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
@@ -9,7 +9,7 @@
import org.bukkit.Effect;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
-import org.bukkit.inventory.EquipmentSlot;
+//import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import com.cryptomorin.xseries.XMaterial;
@@ -33,6 +33,7 @@
import tech.mcprison.prison.spigot.block.PrisonItemStackNotSupportedRuntimeException;
import tech.mcprison.prison.spigot.block.SpigotBlock;
import tech.mcprison.prison.spigot.block.SpigotItemStack;
+import tech.mcprison.prison.spigot.compat.Compatibility.EquipmentSlot;
import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.game.SpigotWorld;
@@ -744,7 +745,8 @@ public MineBombData getBombItem( String bombName ) {
* @return
*/
public boolean setBombInHand( Player player,
- MineBombData bomb, SpigotBlock sBlock, EquipmentSlot hand ) {
+ MineBombData bomb, SpigotBlock sBlock,
+ tech.mcprison.prison.spigot.compat.Compatibility.EquipmentSlot hand ) {
boolean isABomb = false;
// MineBombData bomb = getBombItem( player );
From f244af07d4cc275c5c0b1fe5e84f61f95017debf Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 2 Nov 2022 02:06:10 -0400
Subject: [PATCH 034/129] Added some mine info to the `/prison version command.
---
docs/changelog_v3.3.x.md | 5 ++-
.../prison/spigot/SpigotPlatform.java | 33 +++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 8434db28e..e0e8419ec 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13c 2022-11-01
+# 3.3.0-alpha.13c 2022-11-02
+
+
+* **Added some mine info to the `/prison version command.***
* **Mine Bombs bug fix: Was using a function that was incompatible with bukkit 1.8.8 and this fixes that issue.**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index 7bfb0def5..ae0268c0b 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -2063,6 +2063,38 @@ public List getActiveFeatures( boolean showLaddersAndRanks ) {
}
+ Module minesModule = Prison.get().getModuleManager().getModule( "Mines" ).orElseGet( null );
+ if ( minesModule != null &&
+ minesModule.getStatus().getStatus() == ModuleStatus.Status.ENABLED ) {
+
+ DecimalFormat dFmt = new DecimalFormat("#,##0");
+
+ int minesEnabled = 0;
+ int minesVirtual = 0;
+ int minesDeleted = 0;
+ int minesBlocks = 0;
+
+ List mines = PrisonMines.getInstance().getMines();
+ for (Mine mine : mines) {
+
+ minesEnabled += mine.isEnabled() ? 1 : 0;
+ minesVirtual += mine.isVirtual() ? 1 : 0;
+ minesDeleted += mine.isDeleted() ? 1 : 0;
+
+ minesBlocks += mine.isEnabled() ? mine.getBounds().getTotalBlockCount() : 0;
+ }
+
+ double blksPerMine = minesEnabled == 0 ? 0 : minesBlocks / (double) minesEnabled;
+
+ String mineDetails = String.format(
+ "&7Mines Info: &9Enabled: &b%d &9Virtual: &b%d &9Deleted: &b%d &9AvgBlocks/Mine: &b%s",
+ minesEnabled, minesVirtual, minesDeleted,
+ dFmt.format(blksPerMine) );
+
+ results.add( mineDetails );
+ }
+
+
// Load the autoFeaturesConfig.yml and blockConvertersConfig.json files:
AutoFeaturesWrapper afw = AutoFeaturesWrapper.getInstance();
@@ -2311,6 +2343,7 @@ else if ( !isBasic ) {
display.addText("");
+
// Active Modules:x's root Command: &3/prison");
From 446968c665d857f46f0ee74b0f48b8e4bb38d56f Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 2 Nov 2022 02:08:13 -0400
Subject: [PATCH 035/129] v3.3.0-alpha.13d
---
docs/changelog_v3.3.x.md | 6 +++++-
gradle.properties | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index e0e8419ec..3d64ec8ab 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13c 2022-11-02
+# 3.3.0-alpha.13d 2022-11-02
+
+
+**3.3.0-alpha.13d 2022-11-02**
+NOTE: Changes to PrisonBlock structures have been stashed and are not included in this alpha.13d release.
* **Added some mine info to the `/prison version command.***
diff --git a/gradle.properties b/gradle.properties
index e8a461794..851cd7286 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,7 +3,7 @@
## # This is actually the "correct" place to define the version for the project.
## # Used within build.gradle with ${project.version}.
## # Can be overridden on the command line: gradle -Pversion=3.2.1-alpha.3
-version=3.3.0-alpha.13c
+version=3.3.0-alpha.13d
From f37208f2273bde16e73339fb7f3f63da9a958048 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 2 Nov 2022 06:29:58 -0400
Subject: [PATCH 036/129] Update docs to reflect that prison no longer supports
MVdW.
---
docs/prison_docs_012_setting_up_prison_basics.md | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/docs/prison_docs_012_setting_up_prison_basics.md b/docs/prison_docs_012_setting_up_prison_basics.md
index 5d4d0940f..933ed5ded 100644
--- a/docs/prison_docs_012_setting_up_prison_basics.md
+++ b/docs/prison_docs_012_setting_up_prison_basics.md
@@ -152,10 +152,17 @@ All of Prison's placeholders have an alias. An alias is a shortened name for a
NOTE: You may also need to install the follow plugin for full support: ProtocolLib.
-* **MVdWPlaceholder** - Suggested to Avoid - Prison does support this plugin, but since it is used mostly with premium plugins, we have no way to fully test this plugin to ensure it actually works correctly. We've heard very few people have used this plugin, but we've heard it does work well. Use at your own risk.
-With this plugin, all placeholders are registered with it automatically when prison starts up, and all placeholders should be used as all lower case. Because prison has so many placeholders, with many that are expanded based upon ladders, ranks, and mine names, a modest prison server could generate and register well over 1000 placeholders. MVdWPlaceholder appears to be very verbose so you will see a lot of logging in the console when it starts up.
+* **MVdWPlaceholder** - Not supported.
- It should also be noted that because of some of the limitations of MVdW, not all features of Prison's placeholder support will be supported. For example, you may not be able to reload placeholders, or use placeholder attributes to customize how placeholders are used.
+**NOTE: Prison no longer supports MVdWPlaceholder** because it could not support all of the advanced features with placeholders that prison uses. Also, since prison generates so many possible placeholders, MVdW pollutes the console log with thousands of lines of useless information stating each variant of a placeholder has been registered. We also dropped support for this plugin because there is no way to contact the developer because they hide behind a pay-wall, and I'm not about to buy one of their other plugins to just tell them their so-called-free plugin is not working properly.
+
+But perhaps the biggest reason why I dropped support for MVdW is because it's 100% pointless. **PlaceholderAPI** works flawlessly with MVdW so there is absolutely no reason why prison needs to support MVdW anymore. If you need to use MVdW, then please keep using it, it works great with their other plugins. But you can use PlaceholderAPI along with it too. So there are zero reasons why you cannot use PlaceholderAPI, and everyone is happy.
+
+~~Suggested to Avoid - Prison does support this plugin, but since it is used mostly with premium plugins, we have no way to fully test this plugin to ensure it actually works correctly. We've heard very few people have used this plugin, but we've heard it does work well. Use at your own risk.~~
+
+~~With this plugin, all placeholders are registered with it automatically when prison starts up, and all placeholders should be used as all lower case. Because prison has so many placeholders, with many that are expanded based upon ladders, ranks, and mine names, a modest prison server could generate and register well over 1000 placeholders. MVdWPlaceholder appears to be very verbose so you will see a lot of logging in the console when it starts up.~~
+
+~~ It should also be noted that because of some of the limitations of MVdW, not all features of Prison's placeholder support will be supported. For example, you may not be able to reload placeholders, or use placeholder attributes to customize how placeholders are used.~~
From 587cb2f0398b272d0d4998caf942b3b4777de9a6 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 5 Nov 2022 16:53:03 -0400
Subject: [PATCH 037/129] Update docs on 101 Setting Up Mines
---
...rison_docs_012_setting_up_prison_basics.md | 2 +-
docs/prison_docs_101_setting_up_mines.md | 125 +++++++++++++-----
2 files changed, 91 insertions(+), 36 deletions(-)
diff --git a/docs/prison_docs_012_setting_up_prison_basics.md b/docs/prison_docs_012_setting_up_prison_basics.md
index 933ed5ded..f3cad4b2c 100644
--- a/docs/prison_docs_012_setting_up_prison_basics.md
+++ b/docs/prison_docs_012_setting_up_prison_basics.md
@@ -162,7 +162,7 @@ But perhaps the biggest reason why I dropped support for MVdW is because it's 10
~~With this plugin, all placeholders are registered with it automatically when prison starts up, and all placeholders should be used as all lower case. Because prison has so many placeholders, with many that are expanded based upon ladders, ranks, and mine names, a modest prison server could generate and register well over 1000 placeholders. MVdWPlaceholder appears to be very verbose so you will see a lot of logging in the console when it starts up.~~
-~~ It should also be noted that because of some of the limitations of MVdW, not all features of Prison's placeholder support will be supported. For example, you may not be able to reload placeholders, or use placeholder attributes to customize how placeholders are used.~~
+~~It should also be noted that because of some of the limitations of MVdW, not all features of Prison's placeholder support will be supported. For example, you may not be able to reload placeholders, or use placeholder attributes to customize how placeholders are used.~~
diff --git a/docs/prison_docs_101_setting_up_mines.md b/docs/prison_docs_101_setting_up_mines.md
index 8e467da68..130368d7e 100644
--- a/docs/prison_docs_101_setting_up_mines.md
+++ b/docs/prison_docs_101_setting_up_mines.md
@@ -6,14 +6,22 @@
This document provides some highlights to how to setup mines. It is a work in progress so check back for more information.
+*Documented updated: 2022-11-05*
+
# Overview
-This document should be able to provide the basic information to get your mines configured. There are many options available within Prison, and also through the use of other plugins, and these advanced topics are beyond the scope of this document.
+This document should be able to provide the basic information to get your mines configured. There are many options available within Prison, and also through the use of other plugins, so advanced topics that blend multiple plugins, and their various settings, are beyond the scope of this document.
+
+
+Prison has a list of suggested plugins that works well with Prison, and a few that do not work at all with Prison. Please see the following document for a list of suggested plugins. If you have a favorite plugin that works well with Prison and it's not in that list, then please reach out to us in our discord server and make a suggestion for it to be added.
+[Setting up Prison - The Basics](prison_docs_012_setting_up_prison_basics.md)
+
Items to add to this document:
+* Use of ***/mines backup help** this command will make an individual backup of a mine's config settings on the server's file system. This backup can manually be used to rollback any changes to a mine. Prison has a command **/prison support backup help** that will make a backup of all files within the server directory **plugins/Prison/**, of which it will include all mine backup files, then remove them from file system. Contact support on our discord server for help.
* Use of **/mines set area** to change the mine size without deleting it.
* Use of **/mines delete** how it works and how to recover a deleted mine.
* Use of **/mines list**
@@ -29,11 +37,16 @@ Items to add to this document:
Prison now has a new set of features that can help you get up and running faster than ever! `/ranks autoConfigure`. It can auto create your ranks and virtual mines, A through Z, it will link the mines to the ranks, setup the basic rank commands to provide basic access permissions for your players, and assign blocks of increasing values to all mines. This command also enables the Mine Access Permission so it will be easier to control player's access to mining.
-The Prison auto configure also now enables prison's **sellall** features and preloads about 98 default items to make it easier to get started with your sellall shop.
+The Prison auto configure enables prison's **sellall** features and preloads about 98 default items to make it easier to get started with your sellall shop. It also enable the most popular auto features and links the generated mines to the generated ranks to simplify enabling access for the players.
+
+The auto configure will generate both ranks and mines with the names A through Z, and will link the ranks to the mines of the same names. Prison will setup all the generated mines as virtual mines, which includes the basic configurations that are most commonly used, plus it assigns blocks to each mine, in an increasing range of values. The accessMinesByRanks will also be enabled, which will help bypass the need to generate a WorldGuard region for players to have access to the mines, and will help reduce the need to configure so many perms since Prison will handle the complex relationships for you.
+If you are trying to use Prison with another plugin, such as an enchantment plugin, then you may need to create WG regions because the other plugins would require them.
Once the the auto configure command is completed, all you need to do is to use the command `/mines set area` on all mines to make them physical mines. Plus there are a new features to help provide the finishing touches in almost no time, such as setting liners for your mines.
+The Prison auto configure is very powerful and allows you get up and running much faster, but it does not prevent you from customizing any aspect that you would desire. We strongly encourage everyone to at least start off with the auto configure, play around with it to see what prison can do with these simple setups, then it can help give you an idea of other customizations. It should be noted that auto configure only uses about 10% of the features available within Prison, so as useful as it may be in showing you how to get up and running quickly, there are many other possibilities available where your imagination may be the limiting factor on how your server can be customized to your desires.
+
Some of the commands of interest:
@@ -43,10 +56,8 @@ Some of the commands of interest:
- `/mines set size help`
- `/mines set liner help`
-Documentation pertaining to the use of the auto configuration will be coming soon.
-
-Keep in mind that in order to use the command `/ranks autoConfigure` you cannot have any mines or ranks defined yet. So before you create a test mine, go ahead and run the auto configure so at least that is complete. There is an option to force the generation of auto configure, but when forcing the generation, it will skip over any rank and any mine that is already configured, so it could cause a mess.
+Keep in mind that in order to use the command `/ranks autoConfigure` you should not have any mines or ranks defined yet, which may cause some conflicts with mines and their ranks. So before you create a test mine, go ahead and run the auto configure so at least that is complete. There is an option to force the generation of auto configure, but when forcing the generation, it will skip over any rank and any mine that is already configured, so it could cause a mess.
One thing you need to keep in mind, if you are using something like LuckPerm groups, you must define the groups within LuckPerms before you can actually use them, such as through a rankup command being ran.
@@ -61,15 +72,17 @@ One thing you need to keep in mind, if you are using something like LuckPerm gro
Please review the Prison's [Table of Contents](prison_docs_000_toc.md) for information on how to configure your server, and which plugins are required, or at least suggested.
-It is also strongly suggested that you review the documentation on [Configuring and Using WorldGuard with LuckPerms to Protect Mines](prison_docs_626_configuring_worldguard_regions.md) since that explains a lot on how to setup the basics with your world, which will not be covered here. There will be references to this document, but this will be the only link provided.
+
+Prison now uses **mineAccessByRank** which eliminates the need to setup WorldGuard regions, unless you are using other plugins that require them. If you have a need to setup regions that will work with prison, then it is strongly suggested that you review the documentation on [Configuring and Using WorldGuard with LuckPerms to Protect Mines](prison_docs_626_configuring_worldguard_regions.md) since that explains a lot on how to setup the basics with your world, which will not be covered here. There will be references to this document, but this will be the only link provided.
These instructions assume you are OP'd since that is part of the above document pertaining to WorldGuard. If not, go ahead and OP yourself.
-To follow along with this documentation, you may want to crate your first mine as a test, with intentions of deleting it later. It may be easier to remove it, than to convert it over to a final product. The instructions here are informational, not focused on perfection. So after you figure out how to create your mines, you may want to provide more attention to the details to ensure they are perfect. But for now, the focus is on the commands.
+To follow along with this documentation, you may want to crate your first mine as a test, with intentions of deleting it later. It may be easier to remove it, than to convert it over to a final product. The instructions here are informational, not focused on perfection. So after you figure out how to create your mines, you may want to provide more attention to the details to ensure they are perfect. But for now, the focus is on the commands and better understanding what is possible.
-Please note that all command provide in this document will be written as if they were entered within the game. If you use some of them from the console, then do not include the slash prefix. I always include the slash prefix in the documentation so the commands stand out as being commands.
+Please note that all command provide in this document will be written as if they were entered within the game and will require the leading slash: `/`. If you use these commands within the console, then do not include the slash prefix. I always include the slash prefix in the documentation so the commands stand out as being commands. Personally, I actually prefer to use most commands in the console since there is more room to view the details.
+
+It should also be strongly noted that you should never manually modify the save files for the mines, ranks, or ladders, since that could easily lead to corruption and undefined failures and problems. We cannot support misuse of the files. The primary reason for this concern is that Prison has a rich command interface that provides many checks and balances to ensure the commands are setup correctly. When prison starts up and the configuration files are loaded, those same validations are not performed so serious conflict could be caused by hand modification. That said, if you do adjust the commands by hand, keep in mind these file format of these save files are either yaml or json and therefore if your changes results in invalid yaml or json, then they will not be able to be loaded. We do not support hand edited config issues, but if we have time, we can possibly help identify where the errors are. Keep in mind that if you are having issues, copy and paste the config file that is having issues in to an online lint application: https://jsonlint.com/ or https://codebeautify.org/yaml-validator. There are many to choose from, and they usually help point out where the issue are and provide suggestions on how to fix the errors.
-It should also be strongly noted that you should never modify the save files for the mines, ranks, or ladders, since that could easily lead to corruption and undefined failures and problems. We cannot support misuse of the files.
@@ -78,7 +91,10 @@ It should also be strongly noted that you should never modify the save files for
Being OP'd, find a good location for your mines.
-Also the following commands may help setup the environment. Optional of course. Having some block in your inventory can be useful for use as scaffolding or selecting. I personally like to use sealanterns because they are not a common block and they stand out well in low light conditions and are easier to see in screen prints. Giving yourself `/fly` and `/god` may not be necessary, but it could help if you need to find a good location, or if there are mobs in the area when you drop out of creative mode and back in to survival.
+Also the following commands may help setup the environment. Optional of course. Having some block in your inventory can be useful for use as scaffolding or selecting. I personally like to use `sealanterns` because they are not a common block and they stand out well in low light conditions and are easier to see in screen prints. Giving yourself `/fly` and `/god` may not be necessary, but it could help if you need to find a good location, or if there are mobs in the area when you drop out of creative mode and back in to survival.
+
+
+A few useful commands as OP:
```
/op
@@ -90,6 +106,13 @@ Also the following commands may help setup the environment. Optional of course.
```
+
Command: /ranks autoConfigure>
+
+If you ran the command `/ranks autoConfigure` then all of your mines have been generated and are virtual mines. A virtual mine is one that is fully configured, but it has not been "physically" placed in any world yet. So you can tweak the configurations on the mine, except for setting that relate to any locations within a world. All you have to do with these virtual mines, is to place them.
+
+Below are some of the settings for creating a mine, but since they are already created, you can skip over some of these settings and just jump to placing the mines.
+
+
The wand
Now give yourself a Prison wand.
@@ -98,10 +121,16 @@ Now give yourself a Prison wand.
/mines wand
```
+A mine wand will allow you to set the coordinates of a mine by clicking on a block. You cannot click in air, so you may have to place a block to define the coordinates.
+
+
+A mine wand can also be used for debugging block break actions within a mine. If you are having issues with getting mines to work, it's one of the many built-in support tools that can help figure out what's going wrong, since a prison server can become very complex, especially when factoring in other plugins. Please contact us through our discord server for additional help if needed.
+
+
Laying Out the New Mine
-For the sake of this document, and to keep things simple, the mines we are creating will be very small and will not be deep within the ground.
+For the sake of this document, and to keep things simple, the mines we are creating in these examples and screen prints will be very small and will not be deep within the ground. This will allow for easier understanding of the general layout of what is being created.
First mark out the dimensions of your mine. As you can see here, I've marked my first mine out with sealanterns to show you how big it will be. You really only need to mark opposing corners since that defines a cuboidal region. I've cleared away some of the dirt so you can see the lower blocks. This mine will be 5 x 5 x 5 in size.
@@ -123,7 +152,10 @@ Then create the mine with:
/mines create test1
```
-It will default to 100% air. So then follow up creating the new mine with a reset to confirm everything is replaced with air.
+NOTE: the command `/mines create help` is intended for creating new mines. If you ran `/rank autoConfigure` then the mines already exist, and instead of using `/mines create` you just need to "set" or place the mines with `/mines set area help`.
+
+
+It will default to 100% air. So then follow up creating the new mine with a reset to confirm everything is replaced with air. Mines that are precreated with `/ranks autoConfigure` already have assigned blocks.
@@ -181,35 +213,49 @@ Some of the highlights of these commands are as follows:
* `/mines whereami` : Shows you what mine you are in, or how far away you are from other mines in the area. If you have a lot of mines, it's easy to lose track of where you are, and this may help get your bearings.
+
* `/mines block add` : Add a new block type to a mine. It's easier to start off with `/mines block search` and have it fill in the commands for you.
+* `/mines block constraint` : Controls block generation within a mine, such as minimum number, maximum number, or which layers it can spawn at.
+* `/mines block list` : Shows all blocks within a mine, including the constraints that have been placed on specific blocks. This command is also included in the command `/mines info all`.
* `/mines block remove` : Remove a block type from a mine.
+* `/mines block searchAll` : Search for a block type or item type based up on a search string. This includes all blocks, but also all items too.
* `/mines block search` : Search for a block type based up on a search string.
-* `/mines block set` : Edit the block's percentage within the mine. A percent of zero will remove. If the block does not already exist, it will be added. (Can replace add and remove).
+* `/mines block setChance` : Edit the block's percentage within the mine. A percent of zero will remove the block as if the command `/mines block remove` was used. If the block does not already exist, it will be added. (Can replace add and remove).
+
-* `/mines blockEvent add` :
-* `/mines blockEvent block add` :
-* `/mines blockEvent block list` :
+* `/mines blockEvent add` : This adds one or more commands to a block event. To add multiple commands, just add a semi-colon between the commands: `;`.
+* `/mines blockEvent add placeholders` : This command lists all placeholders that can be used within a block event's commands. These placeholders will expand the flexibility of what other commands can be used.
+* `/mines blockEvent block add` : Adding block type to a blockEvent acts as a filter and will only use this block even on a block type that is listed.
* `/mines blockEvent block remove` :
* `/mines blockEvent eventType` :
-* `/mines blockEvent list` :
-* `/mines blockEvent mode` :
-* `/mines blockEvent percent` :
-* `/mines blockEvent permission` :
+* `/mines blockEvent list` : Use list to how all of the available blockEvents for a given mine. These blockEvent commands that edits a blockEvent are based upon the row number as listed with this command.
+* `/mines blockEvent percent` : Sets the **percent** chance of running this blockEvent. Valid ranges are 100 % which is always ran (if it passes the filters), to as low as 0.00001 percent.
+* `/mines blockEvent permission` : A BlockEvent permission will only allow a blockEvent to be ran if the player has this permission. This filter can be used with other filters, such as "triggered" and "blocks".
* `/mines blockEvent remove` :
-* `/mines blockEvent triggered` :
+* `/mines blockEvent taskMode` : Identifies how a blockEvent is ran. Options are [inline, inlinePlayer, sync, syncPlayer]. "Player" modes runs the command as if the player entered the command and runs under their perms, while non-player modes run as admin as if ran from the console. Inline and sync mode may, or maynot be selectable. Most blockEvents are now ran in another thread and will not hang the BlockBreakEvent anymore, so inline or sync may not have an impact.
+* `/mines blockEvent triggered` : For plugins such as TokenEnchant, their explosion event identifies which enchantment of theirs triggered the event. So this filter can apply a blockEvent to a very specific enchantment.
+
+
+* `/mines set area` : This command places a virtual mine, or it allows you to redefine the area of the mine. Careful, this can wipe out builds if set incorrectly. This is a required command to set the area of the mine. A new feature is to use the current location of your feet to define a 1 x 1 x 1 region with `/mines set area feet`. Then you can use `/mines set size` to make it any size you want.
+* `/mines set area virtual` : This command will remove a mine from a world, and make it virtual. A virtual mine can then be placed somewhere else, or even in a different world. Virtual mines will not try to go through resets, so it's a safe way to disable a mine if you're not ready for it to be active.
+
+
+* `/mines set accessPermission` : Uses permission to enable access to the mine. This does not use the player's rank, which is the suggested method so as to reduce the number of perms that need to be configured and managed.
+* `/mines set mineAccessByRank` : Uses the player's rank to control access to the mines. This is the preferred method of controlling access since it reduces the number of perms that Prison has to manage, and can help bypass the need of using WorldGuard regions to control the players.
+* `/mines set tpAccessByRank` : Uses the player's rank to control the player's ability to teleport to the mine. See the command `/mines tp`.
-* `/mines set area` : Redefine the area of the mine. Careful, this can wipe out builds if set incorrectly. This is a required command to set the area of the mine. A new feature is to use the current location of your feet to define a 1 x 1 x 1 region with `/mines set area feet`. Then you can use `/mines set size` to make it any size you want.
* `/mines set liner` : A quick way to wrap your mine with a 2D Pattern in 3D space. This command also will `repair` the area around a mine, and will effectively erase a liner. There are six directions that can be specified for change: `north`, `south`, `east`, `west`, `top`, and `bottom`. `walls` also is a shortcut for `north`, `south`, `east`, and `west`. The patterns available are listed by the command. There is even a `force` setting that will allow the mine to be wrapped when in air, since the wrappings normally needs blocks in contact with the mine so it is able to conform to the terrain.
-* `/mines set move` is a new command that is not yet enabled. It is still in development, but will be active soon. This command will move a whole mine as a single unit, be it a few blocks or many (not recommended).
-* **Removed:** `/mines set norank` : Disconnect the mine from a rank. **Note:** This command has been changed to `/mines set rank none` to delete the rank from the mine.
+* `/mines set mineSweeper` : If all else fails to get Prison to monitor and track blocks that are broken within a mine, mostly due to conflicts with other plugins, then this option can provide a last chance effort to monitor the progress within a mine. It is very rare that you would have to use this setting and the chances are that there are better ways to get the mines working correctly. The larger the mine, the more costly this setting is to enable.
+* **Removed:** `/mines set move` is a new command that is not yet enabled. It is still in development, but will be active soon. This command will move a whole mine as a single unit, be it a few blocks or many (not recommended). The same effect of moving a mine can be done through the command: `/mine set size` but note it will possibly damage or destory the surrounding builds if not careful.
+* **Removed:** `/mines set norank` : Disconnect the mine from a rank. **Note:** This command has been changed to `/mines set rank *none*` to delete the rank from the mine.
* `/mines set notificationPerm` : Enables or Disables notifications pertaining to mine resets to be seen only by players who have permission to that mine. The permissions used are `mines.notification.[mineName]` in all lower case.
* `/mines set notification` : Can turn off the notifications on a per-mine basis. Or set the notification radius, or only notify players within the mine. This command cannot change the message.
* `/mines set rank ` : Links a mine to a rank, otherwise there is no way within prison to identify which mines should be associated with a given rank. If **rankName** is **none** then it removes the associated rank from the mine (deletes the rank). This is not yet needed, but it will be used in the near future with new features, or enhancements to existing features.
* `/mines set resetThreshold` : This allows you to set a percent remaining in the mine to use as a threshold for resets. For example if you set it to 20.5% then the mine will reset when it reaches 25.5% blocks remaining. When the mine resets, it will initiate the `zeroBlockResetDelay` functionality, of which it's not exactly "zero blocks" anymore.
* `/mines set resetTime` : Changes the time between resets, as expressed in seconds. Applies to each mine independently.
-* `/mines set resetPaging` : This is an advanced feature that can eliminate lag that might be experienced with the resetting of enormous large mines. A mine could be millions of blocks in size and without this setting it may take a few seconds, or longer to reset, and it could cause the ticks to fall far behind, even to the point of forcing a shutdown. This command instead will breakdown the mine's reset in to very small chunks that will prevent the TPS from slowing down, and it will allow other critical tasks to continue to run. The total length of time for the rest may be increased, but it will not hurt the server. Prison does not use async resets due to eventual corruption of the bukkit and spigot components.
+* **Removed:** `/mines set resetPaging` : This no longer is a setting, since Prison always uses a more advanced type of paging that dynamically prevents server lag. This is an advanced feature that can eliminate lag that might be experienced with the resetting of enormous large mines. A mine could be millions of blocks in size and without this setting it may take a few seconds, or longer to reset, and it could cause the ticks to fall far behind, even to the point of forcing a shutdown. This command instead will breakdown the mine's reset in to very small chunks that will prevent the TPS from slowing down, and it will allow other critical tasks to continue to run. The total length of time for the rest may be increased, but it will not hurt the server. Prison does not use async resets due to eventual corruption of the bukkit and spigot components.
* `/mines set size` : Allows you to resize a mine without redefining it with the prison selection wand. Just specify which direction to increase or decrease. It also uses the `/mines set liner repair` feature to fill in voids when reducing an edge.
* `/mines set skipReset` : When enabled, can prevent a mine from resetting if it has no activity. Can set a threshold before the mine is reset, such as 80% will require 20% of the blocks be mined before being reset. Can also set a bypassLimit so that if the reset is skipped X number of times, it will force a reset anyway.
* `/mines set sortOrder` : Mines can be sorted for view within `/mines list` or the GUI. Setting the sortOrder allows you manually set the order in which the mines are listed. There is even the option to suppress (hide) mines from that list too by setting the sort order to a -1.
@@ -218,6 +264,8 @@ Some of the highlights of these commands are as follows:
* `/mines set tracer` : Removes all blocks in a mine and replaces them with air, with the exception of the corners, of which are replace with pink_stained_glass. This function allows for easy viewing of the full mine without the blocks getting in the way. It also helps when setting the liner of the mine. Using `/mines reset` returns the mine to normal functionality, or it will reset on its own.
* `/mines set zeroBlockResetDelay` : If the mine runs out of blocks, when enabled, it will force a manual reset after the specified delay. The delay can be zero for instant reset.
+
+
Adding the term `help` to the end of any of the above listed commands will display additional information that is available for each command, including the parameters and also all permissions that are associated with the commands.
@@ -239,6 +287,7 @@ Let's first take a quick look at the new mine with this command. Let's view it
+The command `/mines info all` provides more details such as the block lists, the commands tied to the mine, and blockEvents for the mine.
Select a Few Blocks
@@ -249,7 +298,10 @@ The easiest way to select blocks is to search for them. Let's add a few such as
/mines block search cobble
```
-
+
+
+Note: `/mines block searchAll` will also include items in the search results. Item are used with the sellall shop and the creation of Mine Bombs items.
+
When using the console with block search limits what you can do with the block search. If you are in game, you can click on a block type that is displayed, and it will auto fill out the block add command for you, such that all you need to do is add the percentage at then end of the command. Also in game, you can page through the results.
@@ -311,18 +363,13 @@ Note: The new command `/mines set move` is not yet enabled. It is still in devel
# Large Mines - Preventing Lag
-Large mines present their special own special challenges, one of which is that they can take a long time to reset. Since bukkit cannot handle async resets of blocks because of world corruption, the updates must happen synchronously in the main server thread. For large mines, that can mean causing a significant amount of lag.
+Large mines present their special own special challenges, one of which is that they can take a long time to reset. Since bukkit cannot handle async resets of blocks because of world corruption, the updates must happen synchronously in the main server thread. For large mines, that can mean causing a significant amount of lag.
-To prevent lagging the server, Prison has a feature that can prevent any lag from happening while performing the reset. This feature is called **Reset Paging**. This feature doesn't have to be used with just large mines, but the reset process is a little more complex. When testing, it was actually found to be slightly faster than the normal reset method.
+To prevent causing lag, Prison now implements a reset paging for all mines. This is an advanced feature that actively monitors the system performance and will auto page when the server load increases, or if the current reset is taking too long. Since this is an active paging feature, that dynamically adjusts for server loads, resetting a lot of mines at the same time, even super-huge mines, would be difficult to cause lag. Even if a lot of other tasks are running on the server, a mine reset cannot lockup the server. As the load increases, the mine resets may take longer to perform, but the ticks per second will not drop by much to cause lag.
-To enable reset paging use the following commands to enable and disable it.
+Paging is where the number of blocks that need to be reset, are broken up in to smaller chunks, or pages. The page sizes are defined to be a certain size, but if performance becomes an issue, then those chunk sizes can be reduced to allow more of the other tasks to run so lag is minimized. This process is active and responds to dynamic server loads as they occur at any stage of the reset. This even will behave well if many mines try to reset at the same time... it can be viewed as like shuffling a deck of cards where one mine will reset a few blocks, then the other mine, and they will take turns until the mines are fully reset. In between each mine, other system tasks, or other plugins can get a chance to run so as to not hog all of the CPU power, which would otherwise lead to lag.
-```
-/mines set resetPaging enable
-/mines set resetPaging disable
-```
-
-The way it works, is that it performs small pages of block updates and keeps an eye on how long it's taking. If the update goes beyond a set amount of time, such as 50 milliseconds, it stops the updates, and then schedules the remaining updates to run later, with no delay. That means if nothing else is trying to run within the main server thread, then it will continue to perform block updates. But if something else was waiting to run, then the mine update will pause and allow the other process to finish. This will prevent vital tasks from backing up because the mine reset yields to other tasks that need to run.
+Prison's paging for mine resets are very much similar to Preemtive Multi-tasking, but instead of bukkit managing the paging, prison itself is managing it's own use of the server's processor to ensure other bukkit tasks, and other plugins, are able to get processing time. It when the bukkit tasks and other plugins are unable to get processing time is when lag becomes an issue and is obvious.
@@ -480,6 +527,14 @@ With it enabled, it shows stats on mine resets in mine list, mine info, and when
+# Virtual Mines and Disabling Mines
+
+Mines can be change to virtual mines or disabled. More information to be provided on these subjects. Please contact us on our discord server for help if needed.
+
+
+
+
+
# Deleting Mines
Mines can be deleted with the `/mines delete` command.
From 5ffacb118a410123a6b3b53d471d6eae1b5c298f Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 10 Nov 2022 19:09:13 -0500
Subject: [PATCH 038/129] Fix issue with world not being removed, or replaced
when the mine is converted to a virtual mine, or when the mine is moved to
another world. The problem would be the config settings for the mine would
save correctly, but upon the server restart, it would revert to the old
world. The problem was with the non-saved world field not being reset
correctly. This fixes the issue correctly so it's should work properly under
all situations.
---
docs/changelog_v3.3.x.md | 6 +-
.../prison/mines/commands/MinesCommands.java | 101 +++++++++++-------
.../mcprison/prison/mines/data/MineData.java | 27 ++++-
3 files changed, 93 insertions(+), 41 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 3d64ec8ab..cead44f48 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13d 2022-11-02
+# 3.3.0-alpha.13d 2022-11-10
+
+
+***Fix issue with world not being removed, or replaced when the mine is converted to a virtual mine, or when the mine is moved to another world.**
+The problem would be the config settings for the mine would save correctly, but upon the server restart, it would revert to the old world. The problem was with the non-saved world field not being reset correctly. This fixes the issue correctly so it's should work properly under all situations.
**3.3.0-alpha.13d 2022-11-02**
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
index dd715c0a0..90311d754 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
@@ -2499,10 +2499,15 @@ else if ( source == null || "virtual".equalsIgnoreCase( source ) ) {
return;
}
+ // Setting bounds to null will also set spawn to null, the two world fields to null, and
+ // make the mine virtual and disale the mine too:
m.setBounds( null );
- m.setSpawn( null );
-
- m.setVirtual( true );
+// m.setSpawn( null );
+//
+// m.setWorld( null );
+// m.setWorldName( null );
+//
+// m.setVirtual( true );
m.getJobStack().clear();
@@ -2533,6 +2538,15 @@ else if ( source == null || "virtual".equalsIgnoreCase( source ) ) {
DecimalFormat dFmt = new DecimalFormat("#,##0");
Bounds selectedBounds = selection.asBounds();
+ if ( Output.get().isDebug() ) {
+ String msg = String.format( "MinesSetArea Preset: Mine: %s Bounds: %s - %s ",
+ m.getName(),
+ selectedBounds.getMin().toWorldCoordinates(),
+ selectedBounds.getMax().toWorldCoordinates()
+ );
+ Output.get().logInfo( msg );
+ }
+
if ( selectedBounds.getTotalBlockCount() > 50000 &&
(options == null || !options.toLowerCase().contains( "confirm" ) &&
!options.toLowerCase().contains( "yes" )) ) {
@@ -2554,10 +2568,22 @@ else if ( options.toLowerCase().contains( "confirm" ) ||
boolean wasVirtual = m.isVirtual();
- // Setting the bounds when it's virtual will configure all the internals:
+
+ // Before setting the bounds, clear everything by setting them to nulls:
+
+ // Setting bounds to null will also set spawn to null, the two world fields to null, and
+ // make the mine virtual and disable the mine too:
+ m.setBounds( null );
+
+ m.getJobStack().clear();
+
+ // Setting the bounds when it's virtual will configure all the internals:
m.setBounds(selectedBounds);
+
+
+
if ( wasVirtual ) {
@@ -2579,44 +2605,47 @@ else if ( options.toLowerCase().contains( "confirm" ) ||
//pMines.getMineManager().clearCache();
// adjustSize to zero to reset set all liners:
- m.adjustSize( Edges.walls, 0 );
-
- if ( options.length() > 0 ) {
- String[] opts = options.split( " " );
+ if ( m.getLinerData() != null ) {
- // Try to set the size of the wall: Increase by:
- if ( opts.length > 0 ) {
- try {
- int size = Integer.parseInt( opts[0] );
- setSizeCommand( sender, mineName, "walls", size );
- }
- catch ( Exception e ) {
- // ignore error
- }
- }
+ m.adjustSize( Edges.walls, 0 );
- // Try to set the size of the bottom: Increase by:
- if ( opts.length > 1 ) {
- try {
- int size = Integer.parseInt( opts[1] );
- setSizeCommand( sender, mineName, "bottom", size );
- }
- catch ( Exception e ) {
- // ignore error
+ if ( options.length() > 0 ) {
+ String[] opts = options.split( " " );
+
+ // Try to set the size of the wall: Increase by:
+ if ( opts.length > 0 ) {
+ try {
+ int size = Integer.parseInt( opts[0] );
+ setSizeCommand( sender, mineName, "walls", size );
+ }
+ catch ( Exception e ) {
+ // ignore error
+ }
}
- }
-
- // Try to set the size of the wall: Increase by:
- if ( opts.length > 2 ) {
- try {
- int size = Integer.parseInt( opts[2] );
- setSizeCommand( sender, mineName, "top", size );
+
+ // Try to set the size of the bottom: Increase by:
+ if ( opts.length > 1 ) {
+ try {
+ int size = Integer.parseInt( opts[1] );
+ setSizeCommand( sender, mineName, "bottom", size );
+ }
+ catch ( Exception e ) {
+ // ignore error
+ }
}
- catch ( Exception e ) {
- // ignore error
+
+ // Try to set the size of the wall: Increase by:
+ if ( opts.length > 2 ) {
+ try {
+ int size = Integer.parseInt( opts[2] );
+ setSizeCommand( sender, mineName, "top", size );
+ }
+ catch ( Exception e ) {
+ // ignore error
+ }
}
+
}
-
}
}
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
index 4de25c311..9fddfe96a 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineData.java
@@ -410,8 +410,16 @@ public Bounds getBounds() {
*
(Re)defines the boundaries for this mine.
*
*
+ *
If the bounds is null, then need to clear both world fields, set to a
+ * virtual mine, and then disable the mine. Failure to clean this up by changing
+ * these fields actually will lock the mine in to a specific world and would not
+ * allow it to be moved to another world. If bounds is set to null, then
+ * spawn is also set to null because a virtual mine cannot have a spawn location.
+ *
+ *
*
This function used to set the world name every time the bounds would
- * change. The world name MUST NEVER be changed. If world is null then it will screw
+ * change. The world name MUST NEVER be changed, unless bounds is null.
+ * If world is null then it will screw
* up the original location of when the was created. World name is set
* in the document loader under Mine.loadFromDocument as the first field
* that is set when restoring from the file.
@@ -422,9 +430,20 @@ public Bounds getBounds() {
public void setBounds(Bounds bounds) {
this.bounds = bounds;
- if ( bounds != null && ( isVirtual() || !getWorld().isPresent() ||
+ // if Bounds is null, then clear out the world fields and set mine to virtual and disable the mine:
+ if ( bounds == null ) {
+
+ setSpawn( null );
+
+ setWorld( null );
+ setWorldName( null );
+ setVirtual( true );
+ setEnabled( false );
+ }
+
+ else if ( isVirtual() || !getWorld().isPresent() ||
getWorldName() == null || getWorldName().trim().length() == 0 ||
- getWorldName().equalsIgnoreCase( "Virtually-Undefined" )) ) {
+ getWorldName().equalsIgnoreCase( "Virtually-Undefined" ) ) {
World world = bounds.getMin().getWorld();
@@ -447,7 +466,7 @@ public void setBounds(Bounds bounds) {
}
// The world name MUST NEVER be changed. If world is null then it will screw
- // up the original location of when the was created. World name is set
+ // up the original location of when the mine was created. World name is set
// in the document loader under Mine.loadFromDocument as the first field
// that is set when restoring from the file.
//this.worldName = bounds.getMin().getWorld().getName();
From c4242b3bf34dc2ac1296575e4364b1bf33cfba2f Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 14 Nov 2022 20:30:40 -0500
Subject: [PATCH 039/129] Add the ability to format the percentage of
prison_rankup_cost_percent with the NFormat placeholder attribute.
---
docs/changelog_v3.3.x.md | 5 ++++-
.../prison/ranks/managers/PlayerManager.java | 15 ++++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index cead44f48..52d5e7fc5 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13d 2022-11-10
+# 3.3.0-alpha.13d 2022-11-11
+
+
+* **Add the ability to format the percentage of prison_rankup_cost_percent with the NFormat placeholder attribute.**
***Fix issue with world not being removed, or replaced when the mine is converted to a virtual mine, or when the mine is moved to another world.**
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
index 6d4fafa18..fba8c9c62 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
@@ -652,7 +652,8 @@ private Rank getNextPrestigeRank( RankPlayer rankPlayer, boolean isDefault, Rank
return results;
}
- public String getPlayerNextRankCostPercent( RankPlayer rankPlayer, String ladderName ) {
+ public String getPlayerNextRankCostPercent( RankPlayer rankPlayer, String ladderName,
+ PlaceholderAttributeNumberFormat attributeNFormat ) {
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
@@ -696,7 +697,15 @@ public String getPlayerNextRankCostPercent( RankPlayer rankPlayer, String ladder
(cost == 0.0d || balance > cost ? 100.0 :
balance / cost * 100.0 )
);
- sb.append( dFmt.format( percent ));
+
+ if ( attributeNFormat != null ) {
+
+ sb.append( attributeNFormat.format( cost ) );
+ }
+ else {
+
+ sb.append( dFmt.format( percent ));
+ }
}
}
}
@@ -1512,7 +1521,7 @@ public String getTranslatePlayerPlaceHolder( PlaceholderIdentifier identifier )
case prison_rankup_cost_percent:
case prison_rcp_laddername:
case prison_rankup_cost_percent_laddername:
- results = getPlayerNextRankCostPercent( rankPlayer, ladderName );
+ results = getPlayerNextRankCostPercent( rankPlayer, ladderName, attributeNFormat );
break;
case prison_rcb:
From d1d70d1c341b3ec84f869c9877f0829db6de38ed Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 14 Nov 2022 20:34:00 -0500
Subject: [PATCH 040/129] New feature: Prestiges placeholder name and tag now
can be assigned to a non-blank space for players that do not have a prestige
rank. This applies to the base placeholders: prison_rank,
prison_rank_laddername, prison_rank_tag, and prison_rank_tag_laddername.
---
docs/changelog_v3.3.x.md | 6 +++++-
.../prison/ranks/managers/PlayerManager.java | 14 ++++++++++++++
prison-spigot/src/main/resources/config.yml | 4 ++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 52d5e7fc5..ac76e5b0b 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,11 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13d 2022-11-11
+# 3.3.0-alpha.13d 2022-11-14
+
+
+* **New feature: Prestiges placeholder name and tag now can be assigned to a non-blank space for players that do not have a prestige rank.**
+This applies to the base placeholders: prison_rank, prison_rank_laddername, prison_rank_tag, and prison_rank_tag_laddername.
* **Add the ability to format the percentage of prison_rankup_cost_percent with the NFormat placeholder attribute.**
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
index fba8c9c62..e76c0dc62 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
@@ -439,6 +439,13 @@ public String getPlayerRankName( RankPlayer rankPlayer, String ladderName ) {
}
}
+ if ( sb.length() == 0 && LadderManager.LADDER_PRESTIGES.equals( ladderName ) ) {
+ // Use config setting for no-prestige-value ladder rank:
+
+ String prestigeEmpty = Prison.get().getPlatform().getConfigString("prestige.no-prestige-value", "");
+ sb.append( prestigeEmpty );
+ }
+
return sb.toString();
}
@@ -528,6 +535,13 @@ public String getPlayerRankTag( RankPlayer rankPlayer, String ladderName ) {
}
}
+ if ( sb.length() == 0 && LadderManager.LADDER_PRESTIGES.equals( ladderName ) ) {
+ // Use config setting for no-prestige-value ladder rank:
+
+ String prestigeEmpty = Prison.get().getPlatform().getConfigString("prestige.no-prestige-value", "");
+ sb.append( prestigeEmpty );
+ }
+
return sb.toString();
}
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 4a5d7176a..82b990f48 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -47,6 +47,9 @@ show-alerts: true
# Confirmation requires action from the player. If GUI is disabled, then it will use
# the command based confiration. If confirm-enabled is false, then no confirmation
# will be used.
+# The value for prestige.no-prestige-value is use when a player has no prestige rank with
+# the base placeholders: prison_rank, prison_rank_laddername, prison_rank_tag, and
+# prison_rank_tag_laddername. If not defined, an empty String is used.
prestige:
enabled: true
resetMoney: true
@@ -54,6 +57,7 @@ prestige:
confirmation-enabled: true
prestige-confirm-gui: true
force-sellall: false
+ no-prestige-value: ""
ranks:
From 9460f4b79bd59ed3b09b71c68b64ccfb61ec1e78 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 21 Nov 2022 01:05:44 -0500
Subject: [PATCH 041/129] v3.3.0-alpha.13e 2022-11-16
---
docs/changelog_v3.3.x.md | 5 ++++-
gradle.properties | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index ac76e5b0b..65cff7f04 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13d 2022-11-14
+# 3.3.0-alpha.13e 2022-11-16
+
+
+**3.3.0-alpha.13e 2022-11-16**
* **New feature: Prestiges placeholder name and tag now can be assigned to a non-blank space for players that do not have a prestige rank.**
diff --git a/gradle.properties b/gradle.properties
index 851cd7286..f1315c465 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,7 +3,7 @@
## # This is actually the "correct" place to define the version for the project.
## # Used within build.gradle with ${project.version}.
## # Can be overridden on the command line: gradle -Pversion=3.2.1-alpha.3
-version=3.3.0-alpha.13d
+version=3.3.0-alpha.13e
From 45ad6ecf108513a83b2b20f0e09b3ffe0f5960e3 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 21 Nov 2022 01:08:07 -0500
Subject: [PATCH 042/129] AutoFeatures: add failure reason when prison is
unable to successfully process a block break event due to zero drops.
---
docs/changelog_v3.3.x.md | 5 ++++-
.../mcprison/prison/spigot/block/OnBlockBreakEventCore.java | 3 +++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 65cff7f04..8498b815b 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,7 +12,10 @@ These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13e 2022-11-16
+# 3.3.0-alpha.13e 2022-11-21
+
+
+* **AutoFeatures: add failure reason when prison is unable to successfully process a block break event due to zero drops.**
**3.3.0-alpha.13e 2022-11-16**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
index ffd69260d..b6810aedf 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
@@ -1003,6 +1003,9 @@ public boolean applyDropsBlockBreakage( PrisonMinesBlockBreakEvent pmEvent, int
if ( totalDrops > 0 ) {
success = true;
}
+ else {
+ debugInfo.append( "(fail:totalDrops=0) ");
+ }
return success;
}
From 8bf4da1365086d6603e5c39d3ac699b733f49e5e Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 3 Dec 2022 22:10:02 -0500
Subject: [PATCH 043/129] Prison API: Add support for direct prison placeholder
support. Two new functions: one translates only one prison placeholder. The
other function takes full text message and will translate multiple prison
placeholders if they are wrapped in placeholder escape characters.
---
docs/changelog_v3.3.x.md | 3 ++
.../prison/spigot/SpigotListener.java | 2 -
.../prison/spigot/api/PrisonSpigotAPI.java | 49 +++++++++++++++++++
3 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 8498b815b..8e2589fb6 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -11,6 +11,9 @@ These build logs represent the work that has been going on within prison.
+* **Prison API: Add support for direct prison placeholder support.**
+Two new functions: one translates only one prison placeholder. The other function takes full text message and will translate multiple prison placeholders if they are wrapped in placeholder escape characters.
+
# 3.3.0-alpha.13e 2022-11-21
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotListener.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotListener.java
index 772c02ab8..632d15fc5 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotListener.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotListener.java
@@ -43,7 +43,6 @@
import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.events.Cancelable;
-import tech.mcprison.prison.internal.events.player.PlayerChatEvent;
import tech.mcprison.prison.internal.events.player.PlayerPickUpItemEvent;
import tech.mcprison.prison.internal.events.player.PlayerSuffocationEvent;
import tech.mcprison.prison.internal.events.player.PrisonPlayerInteractEvent;
@@ -56,7 +55,6 @@
import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.game.SpigotWorld;
-import tech.mcprison.prison.util.ChatColor;
import tech.mcprison.prison.util.Location;
import tech.mcprison.prison.util.Text;
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
index cccccd0b7..d6d3d7b6b 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
@@ -4,8 +4,10 @@
import java.util.List;
import java.util.Optional;
import java.util.TreeMap;
+import java.util.UUID;
import org.bukkit.Material;
+import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@@ -31,7 +33,9 @@
import tech.mcprison.prison.spigot.block.SpigotBlock;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.game.SpigotWorld;
+import tech.mcprison.prison.spigot.placeholder.SpigotPlaceholders;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
+import tech.mcprison.prison.util.ChatColor;
import tech.mcprison.prison.util.Location;
/**
@@ -624,4 +628,49 @@ public void setTokensAdmin( Player player, long amount ) {
}
+ /**
+ *
This function will translate placeholders, but only the specified placeholder.
+ * This cannot contain any placeholder escape characters.
+ *
This function will translate placeholders, and text with placeholders within the text.
+ * You can use any placeholder escape character as long as they are: `% %` or `{ }`.
+ * This can contain multiple placeholders too. This can also include placeholder attributes.
+ *
+ *
+ * @param player
+ * @param identifier
+ * @return
+ */
+ public String getPrisonPlaceholderFullText( OfflinePlayer player, String identifier) {
+
+// if ( !identifier.toLowerCase().startsWith( PlaceholderManager.PRISON_PLACEHOLDER_PREFIX_EXTENDED ) ) {
+// identifier = PlaceholderManager.PRISON_PLACEHOLDER_PREFIX_EXTENDED + identifier;
+// }
+
+ UUID playerUuid = player.getUniqueId();
+ String results = Prison.get().getPlatform().getPlaceholders()
+ .placeholderTranslateText( playerUuid, player.getName(), identifier );
+
+ return ChatColor.translateAlternateColorCodes( '&', results);
+ }
+
}
From 20e5717ba7fc3adf65d3c9d5c6adb4c01514d272 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 3 Dec 2022 22:17:14 -0500
Subject: [PATCH 044/129] Mine reset teleportation can now be controlled within
the config.yml file.
---
docs/changelog_v3.3.x.md | 7 ++---
.../mcprison/prison/mines/MinesListener.java | 26 ++++++++++++-------
.../mcprison/prison/mines/data/MineReset.java | 16 +++++++++---
prison-spigot/src/main/resources/config.yml | 14 ++++++++++
4 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 8e2589fb6..b3f034bfe 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,12 +10,13 @@
These build logs represent the work that has been going on within prison.
+# 3.3.0-alpha.13e 2022-12-03
-* **Prison API: Add support for direct prison placeholder support.**
-Two new functions: one translates only one prison placeholder. The other function takes full text message and will translate multiple prison placeholders if they are wrapped in placeholder escape characters.
+* **Mine reset teleportation can now be controlled within the config.yml file.**
-# 3.3.0-alpha.13e 2022-11-21
+* **Prison API: Add support for direct prison placeholder support.**
+Two new functions: one translates only one prison placeholder. The other function takes full text message and will translate multiple prison placeholders if they are wrapped in placeholder escape characters.
* **AutoFeatures: add failure reason when prison is unable to successfully process a block break event due to zero drops.**
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
index f41385fbc..d38bc7df5 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
@@ -42,17 +42,23 @@ public void onPlayerSuffocationListener( PlayerSuffocationEvent e ) {
if ( mine != null ) {
e.setCanceled( true );
- // Submit the teleport task to run in 3 ticks. This will allow the suffocation
- // event to be canceled. If the player moves then they don't need to be teleported
- // so it will be canceled.
- MineTeleportWarmUpTask mineTeleportWarmUp = new MineTeleportWarmUpTask(
- player, mine, "spawn", 0.5 );
- mineTeleportWarmUp.setMessageSuccess(
- "&7You have been teleported out of the mine to prevent suffocating." );
- mineTeleportWarmUp.setMessageFailed( null );
- PrisonTaskSubmitter.runTaskLater( mineTeleportWarmUp, 3 );
-// mine.teleportPlayerOut( player );
+
+ if ( Prison.get().getPlatform().getConfigBooleanTrue( "prison-mines.tp-to-spawn-on-mine-resets" ) ) {
+
+ // Submit the teleport task to run in 3 ticks. This will allow the suffocation
+ // event to be canceled. If the player moves then they don't need to be teleported
+ // so it will be canceled.
+ MineTeleportWarmUpTask mineTeleportWarmUp = new MineTeleportWarmUpTask(
+ player, mine, "spawn", 0.5 );
+ mineTeleportWarmUp.setMessageSuccess(
+ "&7You have been teleported out of the mine to prevent suffocating." );
+ mineTeleportWarmUp.setMessageFailed( null );
+
+ PrisonTaskSubmitter.runTaskLater( mineTeleportWarmUp, 3 );
+// mine.teleportPlayerOut( player );
+ }
+
//
//
// // To "move" the player out of the mine, they are elevated by one block above the surface
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
index 04fc997af..9b5c04755 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
@@ -893,8 +893,12 @@ public void asynchronouslyResetFinalize( List jobResetActions
// such as could happen if there is lag or a lot going on within the server,
// this will TP anyone out who would otherwise suffocate. I hope! lol
- MineTeleportTask teleportTask = new MineTeleportTask( (Mine) this );
- teleportTask.submitTaskSync();
+
+ if ( Prison.get().getPlatform().getConfigBooleanTrue( "prison-mines.tp-to-spawn-on-mine-resets" ) ) {
+ MineTeleportTask teleportTask = new MineTeleportTask( (Mine) this );
+ teleportTask.submitTaskSync();
+ }
+
// teleportAllPlayersOut();
// setStatsTeleport2TimeMS(
@@ -986,8 +990,12 @@ public boolean resetAsynchonouslyInitiate( MineResetType resetType ) {
canceled = event.isCanceled();
if (!canceled) {
- MineTeleportTask teleportTask = new MineTeleportTask( (Mine) this );
- teleportTask.submitTaskSync();
+
+ if ( Prison.get().getPlatform().getConfigBooleanTrue( "prison-mines.tp-to-spawn-on-mine-resets" ) ) {
+ MineTeleportTask teleportTask = new MineTeleportTask( (Mine) this );
+ teleportTask.submitTaskSync();
+ }
+
// try {
// teleportAllPlayersOut();
//// setStatsTeleport1TimeMS(
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 82b990f48..d5104e4cb 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -161,6 +161,19 @@ top-stats:
# if more than one mine tries to reset at the same time, or close to each
# other. This may be changed to ticks in the near future.
#prison-mines-reset-gap: 5000
+#
+# The tp-warmup will delay the player's attempt to teleport out of a mine,
+# where the delay is in ticks and if they move more than the max distance
+# in blocks, then the TP will be canceled.
+#
+# access-to-prior-mines defaults to true, and if enabled, players will
+# have access to mine in the mines that are tied to ranks that preceeded
+# their current rank. Note, that mines must be tied to ranks to allow
+# this to work.,
+#
+# tp-to-spawn-on-mine-resets: if enabled, players will be TP'd to the mine's
+# spawn location when the mine resets or if they suffocate in the mine.
+# If spawn is not set, then they will be tp'd to the top center of the mine.
prison-mines:
reset-gap-ms: 5000
@@ -177,6 +190,7 @@ prison-mines:
delayInTicks: 20
forced-auto-rankups: false
access-to-prior-mines: true
+ tp-to-spawn-on-mine-resets: true
# Warning: Do not use the following option. This could break the natural Bukkit
From 5cdd66237a7ec347f978c27c125dd3908f996991 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 3 Dec 2022 22:20:11 -0500
Subject: [PATCH 045/129] Mine suffocation can now be enabled so if you turn
off teleportation, then the players can now die.
---
docs/changelog_v3.3.x.md | 3 +++
.../tech/mcprison/prison/mines/MinesListener.java | 15 ++++++++++++++-
prison-spigot/src/main/resources/config.yml | 5 +++++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index b3f034bfe..af4761d20 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13e 2022-12-03
+* **Mine suffocation can now be enabled so if you turn off teleportation, then the players can now die.**
+
+
* **Mine reset teleportation can now be controlled within the config.yml file.**
* **Prison API: Add support for direct prison placeholder support.**
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
index d38bc7df5..4058eab05 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/MinesListener.java
@@ -2,6 +2,7 @@
import com.google.common.eventbus.Subscribe;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.Player;
import tech.mcprison.prison.internal.events.player.PlayerSuffocationEvent;
import tech.mcprison.prison.internal.events.world.PrisonWorldLoadEvent;
@@ -33,6 +34,14 @@ public void onWorldLoadListener( PrisonWorldLoadEvent e ) {
}
+
+ /**
+ *
If a player is suffocating, and if they are within a mine, then based upon the config
+ * settings, the play may not experience suffocation, and they may be teleported to
+ * the mine's spawn location, or the center of the mine.
+ *
+ * @param e
+ */
@Subscribe
public void onPlayerSuffocationListener( PlayerSuffocationEvent e ) {
@@ -40,8 +49,12 @@ public void onPlayerSuffocationListener( PlayerSuffocationEvent e ) {
Mine mine = PrisonMines.getInstance().findMineLocation( player );
if ( mine != null ) {
- e.setCanceled( true );
+ // If players can't be suffocated in mines, then cancel the suffocation event:
+ if ( !Prison.get().getPlatform().getConfigBooleanFalse( "prison-mines.enable-suffocation-in-mines" ) ) {
+
+ e.setCanceled( true );
+ }
if ( Prison.get().getPlatform().getConfigBooleanTrue( "prison-mines.tp-to-spawn-on-mine-resets" ) ) {
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index d5104e4cb..e5350eb34 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -174,6 +174,10 @@ top-stats:
# tp-to-spawn-on-mine-resets: if enabled, players will be TP'd to the mine's
# spawn location when the mine resets or if they suffocate in the mine.
# If spawn is not set, then they will be tp'd to the top center of the mine.
+#
+# enable-suffocation-in-mines: defaults to false so players will not suffocate
+# if they get stuck in a block. Normally this is not an issue since they will
+# be TP'd out, but if that is disabled, then they risk suffocation.
prison-mines:
reset-gap-ms: 5000
@@ -191,6 +195,7 @@ prison-mines:
forced-auto-rankups: false
access-to-prior-mines: true
tp-to-spawn-on-mine-resets: true
+ enable-suffocation-in-mines: false
# Warning: Do not use the following option. This could break the natural Bukkit
From 842b63b293515bc7566fe94a5b3aee6caeb9b9de Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sat, 10 Dec 2022 21:58:36 -0500
Subject: [PATCH 046/129] Setup the control over number formatting by using
Prison as the single source of constructing a DecimalFormat object. This is
done through manually setting the DecimalFormatSymbols to use en_US. It has
also been enabled in config.yml to allow setting the language code that is
used, to any value the admin may wish to use. It's a problem when en_US is
not used, but someone may have a specific reason not to use en_US. Mostly
the primary trouble is related to Minecraft not being able to properly
display NBSP unicode characters.
---
docs/changelog_v3.3.x.md | 6 +-
.../java/tech/mcprison/prison/Prison.java | 64 ++++++++++++++++---
prison-spigot/src/main/resources/config.yml | 23 +++++++
3 files changed, 84 insertions(+), 9 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index af4761d20..5b1d57545 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,11 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13e 2022-12-03
+# 3.3.0-alpha.13e 2022-12-10
+
+
+
+* **Setup the control over number formatting by using Prison as the single source of constructing a DecimalFormat object. This is done through manually setting the DecimalFormatSymbols to use en_US. It has also been enabled in config.yml to allow setting the language code that is used, to any value the admin may wish to use. It's a problem when en_US is not used, but someone may have a specific reason not to use en_US. Mostly the primary trouble is related to Minecraft not being able to properly display NBSP unicode characters.**
* **Mine suffocation can now be enabled so if you turn off teleportation, then the players can now die.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/Prison.java b/prison-core/src/main/java/tech/mcprison/prison/Prison.java
index 7c36a7f80..81c38ba18 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/Prison.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/Prison.java
@@ -20,9 +20,11 @@
import java.io.File;
import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Optional;
import com.google.common.eventbus.EventBus;
@@ -109,6 +111,8 @@ public class Prison
private List localeLoadInfo;
+ private DecimalFormatSymbols dfSym;
+
private Prison() {
super();
@@ -130,7 +134,51 @@ public static Prison get() {
return instance;
}
+ public DecimalFormat getDecimalFormat( String format ) {
+ DecimalFormat dFmt = new DecimalFormat( format, getDecimalFormatSymbols() );
+// DecimalFormat dFmt = new DecimalFormat( format );
+ return dFmt;
+ }
+ public DecimalFormat getDecimalFormatInt() {
+ return getDecimalFormat("#,##0");
+ }
+ public DecimalFormat getDecimalFormatDouble() {
+ return getDecimalFormat("#,##0.000");
+ }
+ /**
+ *
This returns the prison's DecimalFormatSymbols, which controls how the
+ * DecimalFormat is used for various language settings. The en_US language
+ * settings uses a period for decimal place, and a comma for thousands separator.
+ * The issue is with UK, and other countries, that are using a non-breaking
+ * space for the thousands separator since minecraft cannot display that uni-code.
+ * It is shown as a square with NB on the first line, and SP on the second line.
+ *
+ *
+ *
For now, this hard codes prison to use en_US if the config.yml file does not
+ * have a setting "number-format-location: en_US".
+ * It should not use the "default-language"
+ * setting since there needs to be control between the two.
+ *
+ *
+ * @return
+ */
+ private DecimalFormatSymbols getDecimalFormatSymbols() {
+ if ( dfSym == null ) {
+
+ String location = getPlatform().getConfigString( "number-format-location", "en_US" );
+ String[] loc = location.split("_");
+
+ Locale locale = new Locale(
+ loc != null && loc.length >= 1 ? loc[0] : "en",
+ loc != null && loc.length >= 2 ? loc[1] : "US" );
+
+// Locale locale = new Locale( "en", "US" );
+ this.dfSym = new DecimalFormatSymbols( locale );
+ }
+ return dfSym;
+ }
+
/**
* Lazy load LocalManager which ensures Prison is already loaded so
* can get the default language to use from the plugin configs.
@@ -285,7 +333,7 @@ public void displaySystemSettings( ChatDisplay display ) {
long memoryFree = runtime.freeMemory();
long memoryUsed = memoryTotal - memoryFree;
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
+ DecimalFormat dFmt = getDecimalFormatDouble();
String memMax = PlaceholdersUtil.formattedIPrefixBinarySize( memoryMax, dFmt, " " );
String memTotal = PlaceholdersUtil.formattedIPrefixBinarySize( memoryTotal, dFmt, " " );
String memFree = PlaceholdersUtil.formattedIPrefixBinarySize( memoryFree, dFmt, " " );
@@ -329,7 +377,7 @@ public void displaySystemSettings( LinkedHashMap fields ) {
long memoryFree = runtime.freeMemory();
long memoryUsed = memoryTotal - memoryFree;
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
+ DecimalFormat dFmt = getDecimalFormatDouble();
String memMax = PlaceholdersUtil.formattedIPrefixBinarySize( memoryMax, dFmt, " " );
String memTotal = PlaceholdersUtil.formattedIPrefixBinarySize( memoryTotal, dFmt, " " );
String memFree = PlaceholdersUtil.formattedIPrefixBinarySize( memoryFree, dFmt, " " );
@@ -376,7 +424,7 @@ public PrisonStatsUtil getPrisonStatsUtil() {
public void displaySystemTPS( ChatDisplay display ) {
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat iFmt = getDecimalFormatInt();
PrisonTPS prisonTPS = Prison.get().getPrisonTPS();
display.addText( "&7Prison TPS Average: %s Min: %s Max: %s%s " +
"Interval: %s ticks Samples: %s",
@@ -398,7 +446,7 @@ public void displaySystemTPS( ChatDisplay display ) {
}
public void getSystemTPS( LinkedHashMap fields ) {
- //DecimalFormat iFmt = new DecimalFormat("#,##0");
+ //DecimalFormat iFmt = getDecimalFormatInt();
PrisonTPS prisonTPS = Prison.get().getPrisonTPS();
fields.put( "tps", prisonTPS.getAverageTPSFormatted() );
@@ -426,8 +474,8 @@ private void getPrisonDiskSpaceUsage( ChatDisplay display,
calculatePrisonDiskUsage( diskStats, prisonFolder );
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = getDecimalFormatDouble();
+ DecimalFormat iFmt = getDecimalFormatInt();
String prisonFileCount = iFmt.format( diskStats.getFileCount() );
String prisonFolderCount = iFmt.format( diskStats.getFolderCount() );
@@ -450,8 +498,8 @@ public void getPrisonDiskSpaceUsage( LinkedHashMap fields ) {
calculatePrisonDiskUsage( diskStats, prisonFolder );
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = getDecimalFormatDouble();
+ DecimalFormat iFmt = getDecimalFormatInt();
String prisonFileCount = iFmt.format( diskStats.getFileCount() );
// String prisonFolderCount = iFmt.format( diskStats.getFolderCount() );
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index e5350eb34..9c9c82afb 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -131,6 +131,29 @@ placeholder:
default-language: en_US
+
+# Prison defaults to a location code of en_US for the formatting of numbers
+# which uses a "." for the decimal position, and "," for the thousands separator.
+# Prison overries the use of the server's and Java's location code, for the
+# exclusive purpose of formatting numbers, of which may not be
+# controllable by admins if they are using a hosted server.
+# This allows separation between the default_language codes and the
+# number formatting language code.
+# The problem with using some other locations, such as en_UK, is that they
+# may use a Non-Blanking SPace (NBSP) for the thousands separator, of which
+# Minecraft cannot display that uni-code correctly and shows it as a
+# squre with the letters NB on the first line, and SP on the second.
+# Examples of number formatting patterns and the results:
+# #,##0 and #,##0.000
+# 1,000 and 1,000.123
+# This controls number formatting of the symbols used throughout all of
+# prison. This is the only way to control the symbols used. This does not
+# change the use of any of the number formatting patterns.
+number-format-location: en_US
+
+
+
+
# The storage engine that Prison should use to store data.
# The only valid storageType is json.
storageType: "json"
From ddf8846b7861fc94331ad7d8dac207d19c861a46 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 11 Dec 2022 02:16:11 -0500
Subject: [PATCH 047/129] Setup the control over number formatting by using
Prison as the single source of constructing a DecimalFormat object. This is
done through manually setting the DecimalFormatSymbols to use en_US. It has
also been enabled in config.yml to allow setting the language code that is
used, to any value the admin may wish to use. It's a problem when en_US is
not used, but someone may have a specific reason not to use en_US. Mostly
the primary trouble is related to Minecraft not being able to properly
display NBSP unicode characters.
---
.../java/tech/mcprison/prison/PrisonCommand.java | 12 ++++++------
.../tech/mcprison/prison/PrisonCommandMessages.java | 10 +++++-----
.../tech/mcprison/prison/backups/PrisonBackups.java | 6 ++++--
.../mcprison/prison/discord/PrisonPasteChat.java | 5 +++--
.../mcprison/prison/gui/PrisonCoreGuiMessages.java | 10 +++++-----
.../prison/internal/block/PrisonBlockStatusData.java | 4 ++--
.../PlaceholderAttributeNumberFormat.java | 3 ++-
.../prison/placeholders/PlaceholdersStats.java | 6 ++++--
.../prison/placeholders/PlaceholdersUtil.java | 7 ++++---
.../tech/mcprison/prison/ranks/data/RankPlayer.java | 4 ++--
10 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 4c66239a1..27f17d1db 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -726,7 +726,7 @@ public void placeholdersSearchCommand(CommandSender sender,
}
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
builder.add( String.format( "&7 Results: &c%s &7Original patterns: &3%s",
dFmt.format(placeholders.size()), patterns ));
@@ -1495,7 +1495,7 @@ public void backpacksListOldCmd(CommandSender sender
//
// private void addFileToText( File file, StringBuilder sb )
// {
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
// SimpleDateFormat sdFmt = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
//
// sb.append( "\n" );
@@ -1807,7 +1807,7 @@ public void tokensBalance(CommandSender sender,
coreTokensBalanceViewMsg( sender, player.getName(), tokens );
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
// String tokensMsg = dFmt.format( tokens );
//
// String message = String.format( "&3%s has %s tokens.", player.getName(), tokensMsg );
@@ -1851,7 +1851,7 @@ public void tokensAdd( CommandSender sender,
return;
}
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
if ( amount <= 0 ) {
@@ -1949,7 +1949,7 @@ public void tokensRemove( CommandSender sender,
return;
}
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
if ( amount <= 0 ) {
@@ -2037,7 +2037,7 @@ public void tokensSet( CommandSender sender,
return;
}
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
Player player = getPlayer( playerName );
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommandMessages.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommandMessages.java
index 5903b215a..cc6ebeae2 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommandMessages.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommandMessages.java
@@ -43,7 +43,7 @@ protected void coreTokensBalanceCannotViewOthersMsg( CommandSender sender ) {
protected void coreTokensBalanceViewMsg( CommandSender sender, String name, long tokens ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String tokensMsg = dFmt.format( tokens );
Prison.get().getLocaleManager()
@@ -55,7 +55,7 @@ protected void coreTokensBalanceViewMsg( CommandSender sender, String name, long
protected void coreTokensAddInvalidAmountMsg( CommandSender sender, long tokens ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String tokensMsg = dFmt.format( tokens );
Prison.get().getLocaleManager()
@@ -68,7 +68,7 @@ protected void coreTokensAddInvalidAmountMsg( CommandSender sender, long tokens
protected String coreTokensAddedAmountMsg(
String name, long tokens, long amount ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String tokensMsg = dFmt.format( tokens );
String amountMsg = dFmt.format( amount );
@@ -82,7 +82,7 @@ protected String coreTokensAddedAmountMsg(
protected String coreTokensRemovedAmountMsg(
String name, long tokens, long amount ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String tokensMsg = dFmt.format( tokens );
String amountMsg = dFmt.format( amount );
@@ -96,7 +96,7 @@ protected String coreTokensRemovedAmountMsg(
protected String coreTokensSetAmountMsg(
String name, long tokens ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String tokensMsg = dFmt.format( tokens );
return Prison.get().getLocaleManager()
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
index aa546845e..04f17bbf4 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
@@ -40,7 +40,7 @@ public class PrisonBackups {
private ArrayList filesToDelete;
private ArrayList filesWithErrors;
- private DecimalFormat dFmt = new DecimalFormat("#,##0.000");
+ private DecimalFormat dFmt;
private SimpleDateFormat sdFmt = new SimpleDateFormat( "yyyy-MM-dd_kk-mm" );
private SimpleDateFormat sdsFmt = new SimpleDateFormat( "yyyy-MM-dd kk:mm:ss.SSS" );
@@ -54,6 +54,8 @@ public enum BackupTypes {
public PrisonBackups() {
super();
+ this.dFmt = Prison.get().getDecimalFormatDouble();
+
this.filesBackups = new ArrayList<>();
this.filesToBackup = new ArrayList<>();
this.filesToDelete = new ArrayList<>();
@@ -261,7 +263,7 @@ public String startBackup( BackupTypes backupType, String notes ) {
public String backupReport01() {
-// DecimalFormat dFmt = new DecimalFormat("#,##0.000");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatDouble();
long stop = System.nanoTime();
double runTimeMs = ( stop - getStartTimeNanos() ) / 1000000.0d;
diff --git a/prison-core/src/main/java/tech/mcprison/prison/discord/PrisonPasteChat.java b/prison-core/src/main/java/tech/mcprison/prison/discord/PrisonPasteChat.java
index 3ac2fc252..a88baaed2 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/discord/PrisonPasteChat.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/discord/PrisonPasteChat.java
@@ -17,6 +17,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.util.Text;
@@ -163,7 +164,7 @@ protected String cleanText( String text, boolean keepColorCodes )
// // Injects the size back in to the text without changing the total length of the text:
// int size = cleanedText.length();
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
// String sizeString = (dFmt.format( size ) + " bytes ")
// .substring( 0, SUBMISSION_SIZE_PLACEHOLDER.length() );
//
@@ -179,7 +180,7 @@ private String addHeaders( String text ) {
// Injects the size back in to the text without changing the total length of the text:
int size = text.length();
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String sizeString = (dFmt.format( size ) + " bytes ")
.substring( 0, SUBMISSION_SIZE_PLACEHOLDER.length() );
diff --git a/prison-core/src/main/java/tech/mcprison/prison/gui/PrisonCoreGuiMessages.java b/prison-core/src/main/java/tech/mcprison/prison/gui/PrisonCoreGuiMessages.java
index 02cd410d9..35904f79d 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/gui/PrisonCoreGuiMessages.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/gui/PrisonCoreGuiMessages.java
@@ -142,14 +142,14 @@ protected String guiPagePriorMsg() {
protected String guiPriceMsg( Double price ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.00" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.00" );
String value = price == null ? dFmt.format(0) : dFmt.format(price);
return guiPriceMsg( value );
}
protected String guiPriceMsg( Integer price ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String value = price == null ? dFmt.format(0) : dFmt.format(price);
return guiPriceMsg( value );
@@ -165,7 +165,7 @@ protected String guiPriceMsg( String price ) {
protected String guiConfirmMsg( String prestigeName, double value ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.0" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0" );
String valueStr = dFmt.format(value);
return Prison.get().getLocaleManager()
@@ -176,7 +176,7 @@ protected String guiConfirmMsg( String prestigeName, double value ) {
protected String guiDelayMsg( int value ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
String valueStr = dFmt.format(value);
return guiDelayMsg( valueStr );
@@ -191,7 +191,7 @@ protected String guiDelayMsg( String value ) {
protected String guiMultiplierMsg( double value ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.0" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0" );
String valueStr = dFmt.format(value);
return guiMultiplierMsg( valueStr );
diff --git a/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java b/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
index 983f5a0ab..8844ecc11 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/internal/block/PrisonBlockStatusData.java
@@ -201,8 +201,8 @@ public void transferStats( PrisonBlockStatusData oldBlock ) {
public String toPlaceholderString() {
StringBuilder sb = new StringBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0");
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
String percent = fFmt.format(getChance());
diff --git a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholderAttributeNumberFormat.java b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholderAttributeNumberFormat.java
index 3a43e1d82..73c163e36 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholderAttributeNumberFormat.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholderAttributeNumberFormat.java
@@ -5,6 +5,7 @@
import org.apache.commons.lang3.StringUtils;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.placeholders.PlaceholderManager.NumberTransformationUnitTypes;
import tech.mcprison.prison.util.Text;
@@ -182,7 +183,7 @@ public String format( Double value ) {
try {
// & will not work in the DecimalFormat so replace it with ^|^ then replace after formatting:
String fmt = getFormat();//.replace( "&", "^|^" );
- DecimalFormat dFmt = new DecimalFormat( fmt );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( fmt );
switch ( getUnitType() )
{
diff --git a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersStats.java b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersStats.java
index 716de89b7..5f2a6e00d 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersStats.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersStats.java
@@ -5,6 +5,8 @@
import java.util.Collections;
import java.util.TreeMap;
+import tech.mcprison.prison.Prison;
+
public class PlaceholdersStats {
private static PlaceholdersStats stats;
@@ -113,8 +115,8 @@ public PlaceholderStatsData setStats( PlaceholderIdentifier pId, PlaceholderStat
public ArrayList generatePlaceholderReport() {
ArrayList results = new ArrayList<>();
- DecimalFormat iFmt = new DecimalFormat( "#,##0" );
- DecimalFormat dFmt = new DecimalFormat( "#,##0.0000" );
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0000" );
results.add(
"&7 Hits Avg/Hit ms Placeholder" );
diff --git a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersUtil.java b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersUtil.java
index b5ec676b1..a1efb18b4 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersUtil.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/placeholders/PlaceholdersUtil.java
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.util.Text;
public class PlaceholdersUtil
@@ -94,7 +95,7 @@ public static String formattedTime( double timeSec ) {
//
// double secs = (double)(timeSec / TIME_SECOND);
// timeSec -= (secs * TIME_SECOND);
-// DecimalFormat dFmt = new DecimalFormat("#0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("#0");
// sb.append( dFmt.format( secs ));
// // y,m,w,d,h,m,s
// sb.append( prefixesTimeUnits.get(6) ).append( " " );
@@ -116,7 +117,7 @@ public static String formattedTime( double timeSec ) {
*/
public static String formattedMetricSISize( double amount ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
return formattedMetricSISize( amount, dFmt, " " );
}
@@ -156,7 +157,7 @@ private static double divBy1000( double amount, StringBuilder unit, String units
public static String formattedPrefixBinarySize( double amount ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
return formattedIPrefixBinarySize( amount, dFmt, " " );
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
index 507f0e2ef..26c6508d9 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/ranks/data/RankPlayer.java
@@ -1656,7 +1656,7 @@ public static String printRankScoreLine1Header() {
public String printRankScoreLine1( int rankPostion ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
PlayerRank prestRank = getPlayerRankPrestiges();
PlayerRank defRank = getPlayerRankDefault();
@@ -1702,7 +1702,7 @@ public static String printRankScoreLine2Header() {
public String printRankScoreLine2( int rankPostion ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
PlayerRank prestRank = getPlayerRankPrestiges();
PlayerRank defRank = getPlayerRankDefault();
From 6263d235980bf4b3c239897ae34ab2460cb841fb Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 11 Dec 2022 02:20:21 -0500
Subject: [PATCH 048/129] Setup a static version of DecimalFormat which is
needed to be used within all static functions. If the DecimalFormatSymbols
variable is set by a static function, then it will be replaced at the first
chance by a non-static call. The static usage, if not set first by the
non--static calls, cannot access the config.yml settings. This really is not
a problem, since it would only be through unit tests when the gradle build is
being processed that will need the alternative settings.
---
docs/changelog_v3.3.x.md | 7 ++--
.../java/tech/mcprison/prison/Prison.java | 32 +++++++++++++++----
.../java/tech/mcprison/prison/util/Text.java | 14 +++++---
3 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 5b1d57545..3c27dee3c 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,11 +10,14 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13e 2022-12-10
+# 3.3.0-alpha.13e 2022-12-11
+* **Setup a static version of DecimalFormat which is needed to be used within all static functions.** If the DecimalFormatSymbols variable is set by a static function, then it will be replaced at the first chance by a non-static call. The static usage, if not set first by the non--static calls, cannot access the config.yml settings. This really is not a problem, since it would only be through unit tests when the gradle build is being processed that will need the alternative settings.
-* **Setup the control over number formatting by using Prison as the single source of constructing a DecimalFormat object. This is done through manually setting the DecimalFormatSymbols to use en_US. It has also been enabled in config.yml to allow setting the language code that is used, to any value the admin may wish to use. It's a problem when en_US is not used, but someone may have a specific reason not to use en_US. Mostly the primary trouble is related to Minecraft not being able to properly display NBSP unicode characters.**
+
+* **Setup the control over number formatting by using Prison as the single source of constructing a DecimalFormat object.**
+This is done through manually setting the DecimalFormatSymbols to use en_US. It has also been enabled in config.yml to allow setting the language code that is used, to any value the admin may wish to use. It's a problem when en_US is not used, but someone may have a specific reason not to use en_US. Mostly the primary trouble is related to Minecraft not being able to properly display NBSP unicode characters.
* **Mine suffocation can now be enabled so if you turn off teleportation, then the players can now die.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/Prison.java b/prison-core/src/main/java/tech/mcprison/prison/Prison.java
index 81c38ba18..d1ee294a2 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/Prison.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/Prison.java
@@ -111,7 +111,8 @@ public class Prison
private List localeLoadInfo;
- private DecimalFormatSymbols dfSym;
+ private static DecimalFormatSymbols dfSym;
+ private static boolean dfSymStatic = false;
private Prison() {
super();
@@ -136,7 +137,6 @@ public static Prison get() {
public DecimalFormat getDecimalFormat( String format ) {
DecimalFormat dFmt = new DecimalFormat( format, getDecimalFormatSymbols() );
-// DecimalFormat dFmt = new DecimalFormat( format );
return dFmt;
}
public DecimalFormat getDecimalFormatInt() {
@@ -145,6 +145,16 @@ public DecimalFormat getDecimalFormatInt() {
public DecimalFormat getDecimalFormatDouble() {
return getDecimalFormat("#,##0.000");
}
+ public static DecimalFormat getDecimalFormatStatic( String format ) {
+ DecimalFormat dFmt = new DecimalFormat( format, getDecimalFormatSymbolsStatic() );
+ return dFmt;
+ }
+ public static DecimalFormat getDecimalFormatStaticInt() {
+ return getDecimalFormatStatic("#,##0");
+ }
+ public static DecimalFormat getDecimalFormatStaticDouble() {
+ return getDecimalFormatStatic("#,##0.000");
+ }
/**
*
This returns the prison's DecimalFormatSymbols, which controls how the
@@ -164,17 +174,27 @@ public DecimalFormat getDecimalFormatDouble() {
* @return
*/
private DecimalFormatSymbols getDecimalFormatSymbols() {
- if ( dfSym == null ) {
+ if ( dfSym == null || dfSymStatic ) {
- String location = getPlatform().getConfigString( "number-format-location", "en_US" );
+ String location = getPlatform().getConfigString( "number-format-location", "en_US" );
String[] loc = location.split("_");
Locale locale = new Locale(
loc != null && loc.length >= 1 ? loc[0] : "en",
- loc != null && loc.length >= 2 ? loc[1] : "US" );
+ loc != null && loc.length >= 2 ? loc[1] : "US" );
// Locale locale = new Locale( "en", "US" );
- this.dfSym = new DecimalFormatSymbols( locale );
+ dfSym = new DecimalFormatSymbols( locale );
+ dfSymStatic = false;
+ }
+ return dfSym;
+ }
+ private static DecimalFormatSymbols getDecimalFormatSymbolsStatic() {
+ if ( dfSym == null ) {
+
+ Locale locale = new Locale( "en", "US" );
+ dfSym = new DecimalFormatSymbols( locale );
+ dfSymStatic = true;
}
return dfSym;
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/Text.java b/prison-core/src/main/java/tech/mcprison/prison/util/Text.java
index ab5606696..01088b199 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/Text.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/Text.java
@@ -89,10 +89,14 @@ public class Text
//#([A-Fa-f0-9]){6}
- private static DecimalFormat dFmt = new DecimalFormat("#,##0.00");
- private static DecimalFormat iFmt = new DecimalFormat("#,##0");
+ private static DecimalFormat dFmt = Prison.getDecimalFormatStatic("#,##0.00");
+ private static DecimalFormat iFmt = Prison.getDecimalFormatStaticInt();
-
+ static {
+ if ( Prison.get() != null ) {
+
+ }
+ }
protected Text() {
super();
@@ -627,8 +631,8 @@ public static String pluralize(String baseNoun, int quantity) {
public static String formatTimeDaysHhMmSs( long timeMs ) {
- DecimalFormat iFmt = new DecimalFormat("#,##0");
- DecimalFormat tFmt = new DecimalFormat("00");
+ DecimalFormat iFmt = Prison.getDecimalFormatStaticInt();
+ DecimalFormat tFmt = Prison.getDecimalFormatStatic("00");
// SimpleDateFormat sdFmt = new SimpleDateFormat( "HH:mm:ss" );
// long _sec = 1000;
From 7f76805924dd09f1872f76731d1ab9cc6491aa8f Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 11 Dec 2022 02:22:34 -0500
Subject: [PATCH 049/129] Setup the control over number formatting by using
Prison as the single source of constructing a DecimalFormat object. This is
done through manually setting the DecimalFormatSymbols to use en_US. It has
also been enabled in config.yml to allow setting the language code that is
used, to any value the admin may wish to use. It's a problem when en_US is
not used, but someone may have a specific reason not to use en_US. Mostly
the primary trouble is related to Minecraft not being able to properly
display NBSP unicode characters.
---
.../prison/tasks/PrisonCommandTaskData.java | 3 +-
.../mcprison/prison/util/PrisonStatsUtil.java | 2 +-
.../tech/mcprison/prison/util/PrisonTPS.java | 3 +-
.../mines/commands/MinesBlockCommands.java | 8 ++---
.../prison/mines/commands/MinesCommands.java | 30 +++++++++----------
.../mcprison/prison/mines/data/MineReset.java | 10 +++----
.../prison/mines/data/MineScheduler.java | 2 +-
...StartupRefreshBlockBreakCountSyncTask.java | 5 ++--
.../prison/mines/features/MineBlockEvent.java | 2 +-
.../prison/mines/managers/MineManager.java | 6 ++--
.../tech/mcprison/prison/ranks/RankUtil.java | 6 ++--
.../prison/ranks/commands/LadderCommands.java | 2 +-
.../commands/LadderCommandsMessages.java | 7 +++--
.../prison/ranks/commands/RanksCommands.java | 20 ++++++-------
.../ranks/commands/RanksCommandsMessages.java | 11 +++----
15 files changed, 61 insertions(+), 56 deletions(-)
diff --git a/prison-core/src/main/java/tech/mcprison/prison/tasks/PrisonCommandTaskData.java b/prison-core/src/main/java/tech/mcprison/prison/tasks/PrisonCommandTaskData.java
index cece36ab8..3c4c20f8d 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/tasks/PrisonCommandTaskData.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/tasks/PrisonCommandTaskData.java
@@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.List;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.PrisonAPI;
import tech.mcprison.prison.internal.Player;
import tech.mcprison.prison.output.Output;
@@ -300,7 +301,7 @@ public String getDebugDetails() {
long nanoTotal = 0;
- DecimalFormat dFmt = new DecimalFormat( "#,000.0000" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,000.0000" );
for ( Long elapsedNano : elapsedTimes )
{
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonStatsUtil.java b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonStatsUtil.java
index 692770c62..56857746c 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonStatsUtil.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonStatsUtil.java
@@ -220,7 +220,7 @@ private List listFiles(String path, String fileSuffix) {
}
private void addFileToText(File file, StringBuilder sb) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
SimpleDateFormat sdFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sb.append("\n");
diff --git a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonTPS.java b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonTPS.java
index 84e4326e9..aab73a7a5 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/util/PrisonTPS.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/util/PrisonTPS.java
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.tasks.PrisonRunnable;
import tech.mcprison.prison.tasks.PrisonTaskSubmitter;
@@ -200,7 +201,7 @@ public class PrisonTPS
private transient long lastPollNano = System.nanoTime();
- private final DecimalFormat tpsFmt = new DecimalFormat("#,##0.00");
+ private final DecimalFormat tpsFmt = Prison.get().getDecimalFormat("#,##0.00");
public static final Object tpsLock = new Object();
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesBlockCommands.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesBlockCommands.java
index dd14006c9..f4ae83f64 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesBlockCommands.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesBlockCommands.java
@@ -161,8 +161,8 @@ protected BulletedListComponent getBlocksList( Mine m, CommandPagedData cmdPageD
BulletedListComponent.BulletedListBuilder builder = new BulletedListComponent.BulletedListBuilder();
- DecimalFormat iFmt = new DecimalFormat( "#,##0" );
- DecimalFormat dFmt = new DecimalFormat( "#,##0.00" );
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.00" );
double totalChance = 0.0d;
int count = 0;
@@ -658,8 +658,8 @@ public void listBlockCommand(CommandSender sender,
return;
}
- DecimalFormat dFmt = new DecimalFormat("#,##0");
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
ChatDisplay chatDisplay = new ChatDisplay("&bMine: &3" + m.getName());
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
index 90311d754..7560bde9b 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java
@@ -893,8 +893,8 @@ public void allMinesInfoDetails( StringBuilder sb ) {
private ChatDisplay mineInfoDetails( CommandSender sender, boolean isMineStats, Mine m, CommandPagedData cmdPageData )
{
- DecimalFormat dFmt = new DecimalFormat("#,##0");
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
ChatDisplay chatDisplay = new ChatDisplay("&bMine: &3" + m.getName());
@@ -1467,8 +1467,8 @@ private BulletedListComponent getMinesLineItemList( PrisonSortableResults sorted
new BulletedListComponent.BulletedListBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0");
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
int count = 0;
@@ -1963,7 +1963,7 @@ public void zeroBlockResetDelayCommand(CommandSender sender,
pMines.getMineManager().saveMine( m );
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
// User's message:
if ( m.isZeroBlockResetDisabled() ) {
Output.get().sendInfo( sender, "&7Mine &b%s Zero Block Reset Delay: &cDISABLED",
@@ -2052,8 +2052,8 @@ public void resetThresholdPercentCommand(CommandSender sender,
m.getBounds().getTotalBlockCount() *
m.getResetThresholdPercent() / 100.0d;
- DecimalFormat dFmt = new DecimalFormat("#,##0");
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
// User's message:
String message = String.format( "&7The Reset Threshold Percent for mine &b%s&7 was set to &b%s&7, " +
@@ -2104,7 +2104,7 @@ public void setNotificationCommand(CommandSender sender,
if ( noteRadius < 1 ) {
noteRadius = MineData.MINE_RESET__BROADCAST_RADIUS_BLOCKS;
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
Output.get().sendWarn( sender, "&7Invalid radius value. " +
"Must be an positive non-zero integer. Using the default value: &b%s &7[&b%s&7]",
dFmt.format(MineData.MINE_RESET__BROADCAST_RADIUS_BLOCKS), radius );
@@ -2166,7 +2166,7 @@ private boolean changeMineNotification( CommandSender sender, String mineName,
pMines.getMineManager().saveMine( m );
success = true;
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
// message: notification mode changed
Output.get().sendInfo( sender, "&7Notification mode was changed for &b%s&7: &b%s %s",
mineName, m.getNotificationMode().name(),
@@ -2535,7 +2535,7 @@ else if ( source == null || "virtual".equalsIgnoreCase( source ) ) {
return;
}
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
Bounds selectedBounds = selection.asBounds();
if ( Output.get().isDebug() ) {
@@ -3338,7 +3338,7 @@ else if ( !mine.isVirtual() && mine.getBounds().within( player.getLocation(),
if ( lookingAtMine != null ) {
double distance = lookingAtMine.getBounds().getDistance3d( player.getLocation() );
- DecimalFormat dFmt = new DecimalFormat("#,##0.0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.0");
sender.sendMessage( String.format( "&3You are looking at mine &7%s &3which is &7%s &3blocks away.",
lookingAtMine.getTag(), dFmt.format( distance ) ) );
}
@@ -3446,7 +3446,7 @@ private void generateBlockEventListing( Mine m, ChatDisplay display, boolean inc
BulletedListComponent.BulletedListBuilder builder =
new BulletedListComponent.BulletedListBuilder();
- DecimalFormat dFmt = new DecimalFormat("0.00000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("0.00000");
int rowNumber = 0;
for (MineBlockEvent blockEvent : m.getBlockEvents()) {
@@ -3868,7 +3868,7 @@ public void blockEventPercent(CommandSender sender,
// Save the mine:
pMines.getMineManager().saveMine( m );
- DecimalFormat dFmt = new DecimalFormat("0.00000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("0.00000");
Output.get().sendInfo(sender, "&7BlockEvent percentage &b%s&7 was changed for mine '&b%s&7'. " +
"Was &b%s&7. Command '&b%s&7'",
dFmt.format( chance ), m.getTag(),
@@ -4412,7 +4412,7 @@ public void blockEventBlockAdd(CommandSender sender,
display.addText("&8Select a block from this mine by using the block's row number:");
display.addText("&8 " + commandBlockEvent + " [rowBlockName]");
- DecimalFormat dFmt = new DecimalFormat("0.00000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("0.00000");
// Display a list of blocks for the mine:
int blockRow = 0;
@@ -4574,7 +4574,7 @@ public void blockEventBlockRemove(CommandSender sender,
display.addText("&8Select a block filter from this mine by using the block's row number:");
display.addText("&8 " + commandBlockEvent + " [rowBlockName]");
-// DecimalFormat dFmt = new DecimalFormat("0.00000");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("0.00000");
// Display a list of blocks for the mine:
int blockRow = 0;
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
index 9b5c04755..e1275d57f 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineReset.java
@@ -197,7 +197,7 @@ protected void initialize() {
//
// // Tie to the command stats mode so it logs it if stats are enabled:
// if ( PrisonMines.getInstance().getMineManager().isMineStats() ) {
-// DecimalFormat dFmt = new DecimalFormat("#,##0");
+// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
// Output.get().logInfo("&cMine reset: &7" + getTag() +
// "&c Blocks: &7" + dFmt.format( getBounds().getTotalBlockCount() ) +
// statsMessage() );
@@ -340,8 +340,8 @@ protected void initialize() {
public String statsMessage() {
StringBuilder sb = new StringBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatDouble();
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
sb.append( "&3 ResetTime: &7" );
sb.append( dFmt.format(getStatsResetTimeMS() / 1000.0d )).append( " s " );
@@ -819,7 +819,7 @@ public void generateBlockListAsync() {
//// // Tie to the command stats mode so it logs it if stats are enabled:
//// if ( PrisonMines.getInstance().getMineManager().isMineStats() ||
//// getCurrentJob().getResetActions().contains( MineResetActions.DETAILS ) ) {
-//// DecimalFormat dFmt = new DecimalFormat("#,##0");
+//// DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
//// Output.get().logInfo("&cMine reset: &7" + getTag() +
//// "&c Blocks: &7" + dFmt.format( getBounds().getTotalBlockCount() ) +
//// statsMessage() );
@@ -950,7 +950,7 @@ public void asynchronouslyResetFinalize( List jobResetActions
// Tie to the command stats mode so it logs it if stats are enabled:
if ( PrisonMines.getInstance().getMineManager().isMineStats() ||
getCurrentJob().getResetActions().contains( MineResetActions.DETAILS ) ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
Output.get().logInfo("&cMine reset: &7" + getTag() +
"&c Blocks: &7" + dFmt.format( getBounds().getTotalBlockCount() ) +
statsMessage() );
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineScheduler.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineScheduler.java
index 8ded47dfa..cf68899db 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineScheduler.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/MineScheduler.java
@@ -623,7 +623,7 @@ private void processBlockEventDetails( Player player, PrisonBlock prisonBlock,
perms.trim().length() == 0
) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.0000" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0000" );
PrisonBlockStatusData originalBlock = targetBlock.getPrisonBlock();
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/OnStartupRefreshBlockBreakCountSyncTask.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/OnStartupRefreshBlockBreakCountSyncTask.java
index c02cf30a8..7c866ab23 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/data/OnStartupRefreshBlockBreakCountSyncTask.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/data/OnStartupRefreshBlockBreakCountSyncTask.java
@@ -3,6 +3,7 @@
import java.text.DecimalFormat;
import java.util.List;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.tasks.PrisonRunnable;
import tech.mcprison.prison.util.Location;
@@ -110,8 +111,8 @@ public void run() {
mine.setAirCountTimestamp( System.currentTimeMillis() );
if ( Output.get().isDebug() ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.000");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatDouble();
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
String message = String.format(
"MineReset startup air-count: Mine: %-6s " +
" blocks: %10s pages: %s elapsed %s ms",
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/features/MineBlockEvent.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/features/MineBlockEvent.java
index cf5ad9b9d..874a43971 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/features/MineBlockEvent.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/features/MineBlockEvent.java
@@ -151,7 +151,7 @@ public String toSaveString() {
}
nFmt.format( getChance() );
-// DecimalFormat dFmt = new DecimalFormat("0.00000");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("0.00000");
return nFmt.format( getChance() ) + "|" +
(getPermission() == null || getPermission().trim().length() == 0 ?
diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/managers/MineManager.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/managers/MineManager.java
index c44b302ba..91e6ea570 100644
--- a/prison-mines/src/main/java/tech/mcprison/prison/mines/managers/MineManager.java
+++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/managers/MineManager.java
@@ -791,9 +791,9 @@ public String getTranslateMinesPlaceholder( PlaceholderIdentifier identifier ) {
if ( mine != null ||
placeHolderKey.getPlaceholder().hasFlag( PlaceholderFlags.PLAYERBLOCKS ) ||
placeHolderKey.getPlaceholder().hasFlag( PlaceholderFlags.MINEPLAYERS )) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
-// DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+// DecimalFormat fFmt = Prison.get().getDecimalForma("#,##0.00");
identifier.setFoundAMatch( true );
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/RankUtil.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/RankUtil.java
index edc8a3338..642d26442 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/RankUtil.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/RankUtil.java
@@ -900,8 +900,8 @@ else if (LadderManager.LADDER_DEFAULT.equalsIgnoreCase( results.getLadder().getN
private void logTransactionResults( RankupResults results )
{
StringBuilder sb = new StringBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
Rank oRank = results.getOriginalRank();
PlayerRank opRank = results.getPlayerRankOriginal();
@@ -966,7 +966,7 @@ private void logTransactionResults( RankupResults results )
case accuracy_out_of_range:
sb.append( "=" );
- DecimalFormat sFmt = new DecimalFormat("#,##0.00000000");
+ DecimalFormat sFmt = Prison.get().getDecimalFormat("#,##0.00000000");
sb.append( sFmt.format( results.getRankupCostFinalAccuracy() ) );
break;
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommands.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommands.java
index 2da228046..4e166ba48 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommands.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommands.java
@@ -99,7 +99,7 @@ public void ladderList(CommandSender sender) {
BulletedListComponent.BulletedListBuilder list =
new BulletedListComponent.BulletedListBuilder();
-// DecimalFormat dFmt = new DecimalFormat( "#,##0.0000" );
+// DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0000" );
// String header = String.format(
// "&d%-12s %16s %5s %12s %12s",
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommandsMessages.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommandsMessages.java
index c08c64ce6..66b5c5498 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommandsMessages.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/LadderCommandsMessages.java
@@ -2,6 +2,7 @@
import java.text.DecimalFormat;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.commands.BaseCommands;
import tech.mcprison.prison.internal.CommandSender;
import tech.mcprison.prison.ranks.PrisonRanks;
@@ -178,7 +179,7 @@ protected void ladderSetRankCostMultiplierSavedMsg( CommandSender sender, String
double rankCostMultiplier, double oldRankCostMultiplier )
{
- DecimalFormat fFmt = new DecimalFormat("#,##0.00000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00000");
PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_LadderCommands__ladder_set_rank_cost_multiplier" )
@@ -193,7 +194,7 @@ protected void ladderSetRankCostMultiplierNoChangeMsg( CommandSender sender, Str
double rankCostMultiplier )
{
- DecimalFormat fFmt = new DecimalFormat("#,##0.00000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00000");
PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_LadderCommands__ladder_rank_cost_multiplier_no_change" )
@@ -207,7 +208,7 @@ protected void ladderSetRankCostMultiplierOutOfRangeMsg( CommandSender sender,
double rankCostMultiplier )
{
- DecimalFormat fFmt = new DecimalFormat("#,##0.00000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00000");
PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_LadderCommands__ladder_rank_cost_multiplier_out_of_range" )
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommands.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommands.java
index f3f3abe79..1185492f6 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommands.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommands.java
@@ -858,7 +858,7 @@ private ChatDisplay listRanksOnLadder( RankLadder ladder, boolean hasPerm, RankP
BulletedListComponent.BulletedListBuilder builder =
new BulletedListComponent.BulletedListBuilder();
- DecimalFormat fFmt = new DecimalFormat("#,##0.0000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.0000");
// Here's the deal... With color codes, Java's String.format() cannot detect the correct
// length of a tag. So go through all tags, strip the colors, and see how long they are.
@@ -1212,7 +1212,7 @@ private ChatDisplay rankInfoDetails( CommandSender sender, Rank rank, String opt
// Add the raw ladder rank multiplier here:
- DecimalFormat fFmt = new DecimalFormat("#,##0.0000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.0000");
// The following is the rank adjusted rank multiplier
@@ -1472,10 +1472,10 @@ public void rankPlayer(CommandSender sender,
List msgs = new ArrayList<>();
- DecimalFormat iFmt = new DecimalFormat("#,##0");
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
- DecimalFormat fFmt = new DecimalFormat("0.0000");
- DecimalFormat pFmt = new DecimalFormat("#,##0.0000");
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("0.0000");
+ DecimalFormat pFmt = Prison.get().getDecimalFormat("#,##0.0000");
SimpleDateFormat sdFmt = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
@@ -1518,7 +1518,7 @@ public void rankPlayer(CommandSender sender,
if ( rankPlayer != null ) {
-// DecimalFormat iFmt = new DecimalFormat("#,##0");
+// DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
//
// SimpleDateFormat sdFmt = new SimpleDateFormat( "HH:mm:ss" );
@@ -1804,8 +1804,8 @@ public void rankPlayer(CommandSender sender,
// private String formatTimeMs( long timeMs ) {
//
-// DecimalFormat iFmt = new DecimalFormat("#,##0");
-// DecimalFormat tFmt = new DecimalFormat("00");
+// DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+// DecimalFormat tFmt = Prison.get().getDecimalFormat("00");
//// SimpleDateFormat sdFmt = new SimpleDateFormat( "HH:mm:ss" );
//
// long _sec = 1000;
@@ -2127,7 +2127,7 @@ public void rankTopN(CommandSender sender,
int posStart = (page - 1) * pageSize;
int posEnd = posStart + pageSize;
-// DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
// if ( sort ) {
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommandsMessages.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommandsMessages.java
index 4fbcc41a0..0b540619e 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommandsMessages.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RanksCommandsMessages.java
@@ -2,6 +2,7 @@
import java.text.DecimalFormat;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.commands.BaseCommands;
import tech.mcprison.prison.internal.CommandSender;
import tech.mcprison.prison.output.LogLevel;
@@ -138,7 +139,7 @@ protected void autoConfigNoRanksCreatedMsg( CommandSender sender ) {
protected void autoConfigLadderRankCostMultiplierInfoMsg( CommandSender sender,
double rankCostMultiplier ) {
- DecimalFormat dFmt = new DecimalFormat("0.0000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("0.0000");
PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_rankCommands__auto_config_ladder_rank_cost_multiplier_info" )
@@ -245,7 +246,7 @@ protected String ranksListHeaderMsg( String ladderName) {
protected String ranksListLadderCostMultiplierMsg( double multiplier ) {
- DecimalFormat fFmt = new DecimalFormat("#,##0.0000");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.0000");
return PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_rankCommands__ranks_list_ladder_cost_multplier" )
@@ -369,7 +370,7 @@ protected String ranksInfoLinkedMinesMsg( String mines ) {
}
protected String ranksInfoCostMsg( double cost ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
return PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_rankCommands__ranks_info_cost" )
.withReplacements(
@@ -386,7 +387,7 @@ protected String ranksInfoCurrencyMsg( String currency ) {
}
protected String ranksInfoPlayersWithRankMsg( double playerCount ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
return PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_rankCommands__ranks_info_players_with_rank" )
.withReplacements(
@@ -416,7 +417,7 @@ protected String ranksInfoRankDeleteToolTipMsg() {
protected void rankSetCostSuccessfulMsg( CommandSender sender,
String rankName, double cost ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
PrisonRanks.getInstance().getRanksMessages()
.getLocalizable( "ranks_rankCommands__rank_set_cost_success" )
.withReplacements(
From eb78b94bd32fb45839d520bc7aa2779b0dfed402 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 11 Dec 2022 02:24:08 -0500
Subject: [PATCH 050/129] Setup the control over number formatting by using
Prison as the single source of constructing a DecimalFormat object. This is
done through manually setting the DecimalFormatSymbols to use en_US. It has
also been enabled in config.yml to allow setting the language code that is
used, to any value the admin may wish to use. It's a problem when en_US is
not used, but someone may have a specific reason not to use en_US. Mostly
the primary trouble is related to Minecraft not being able to properly
display NBSP unicode characters.
---
.../prison/ranks/managers/LadderManager.java | 3 ++-
.../prison/ranks/managers/PlayerManager.java | 22 +++++++++----------
.../prison/ranks/managers/RankManager.java | 5 +++--
.../prison/spigot/SpigotPlatform.java | 5 ++---
.../prison/spigot/api/PrisonSpigotAPI.java | 1 -
.../autofeatures/AutoManagerFeatures.java | 9 ++++----
.../spigot/block/OnBlockBreakEventCore.java | 2 +-
.../commands/PrisonSpigotSellAllCommands.java | 4 ++--
.../spigot/economies/VaultEconomyWrapper.java | 5 +++--
.../spigot/gui/mine/SpigotMinesGUI.java | 5 +++--
.../spigot/gui/mine/SpigotPlayerMinesGUI.java | 3 ++-
.../spigot/gui/rank/SpigotPlayerRanksGUI.java | 4 ++--
.../spigot/gui/rank/SpigotRankManagerGUI.java | 3 ++-
.../spigot/gui/rank/SpigotRanksGUI.java | 3 ++-
.../prison/spigot/sellall/SellAllUtil.java | 14 ++++++------
.../spigot/slime/SlimeBlockFunEventData.java | 5 +++--
.../slime/SlimeBlockFunEventListener.java | 3 ++-
.../spigot/utils/PrisonUtilsMineBombs.java | 2 +-
.../utils/PrisonUtilsMineBombsMessages.java | 3 ++-
.../utils/PrisonUtilsMineBombsTasks.java | 3 ++-
20 files changed, 57 insertions(+), 47 deletions(-)
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/LadderManager.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/LadderManager.java
index 2e9d420f0..b2613746c 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/LadderManager.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/LadderManager.java
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.stream.Collectors;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.ranks.PrisonRanks;
import tech.mcprison.prison.ranks.data.Rank;
@@ -350,7 +351,7 @@ public String printRankLadderInfoHeader() {
public String printRankLadderInfoDetail( RankLadder ladder ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.0000" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.0000" );
int rankCount = ladder.getRanks() == null ? 0 : ladder.getRanks().size();
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
index e76c0dc62..1856f2336 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/PlayerManager.java
@@ -583,7 +583,7 @@ public String getPlayerNextRankCost( RankPlayer rankPlayer, String ladderName,
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -671,7 +671,7 @@ public String getPlayerNextRankCostPercent( RankPlayer rankPlayer, String ladder
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -735,7 +735,7 @@ public String getPlayerNextRankCostBar( RankPlayer rankPlayer, String ladderName
if ( !rankPlayer.getLadderRanks().isEmpty()) {
-// DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -801,7 +801,7 @@ public String getPlayerNextRankCostRemaining( RankPlayer rankPlayer, String ladd
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -871,7 +871,7 @@ public String getPlayerNextRankCostRemainingPercent( RankPlayer rankPlayer, Stri
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -935,7 +935,7 @@ public String getPlayerNextRankCostRemainingBar( RankPlayer rankPlayer, String l
StringBuilder sb = new StringBuilder();
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- // DecimalFormat dFmt = new DecimalFormat("#,##0");
+ // DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -1032,7 +1032,7 @@ private String getPlayerBalance( RankPlayer rankPlayer, String ladderName,
// }
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
@@ -1075,7 +1075,7 @@ private String getPlayerAverageEarningsPerMinute( RankPlayer rankPlayer, String
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
double epm = PlayerCache.getInstance().getPlayerEarningsPerMinute( rankPlayer );
@@ -1101,7 +1101,7 @@ private String getPlayerTokenBalance( RankPlayer rankPlayer,
int formatMode, PlaceholderAttributeNumberFormat attributeNFormat ) {
StringBuilder sb = new StringBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
long tokens = rankPlayer.getPlayerCachePlayerData().getTokens();
@@ -1150,7 +1150,7 @@ private String getPlayerTokenAverageEarningsPerMinute( RankPlayer rankPlayer,
if ( !rankPlayer.getLadderRanks().isEmpty()) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
double tpm = rankPlayer.getPlayerCachePlayerData().getAverageTokensPerMinute();
@@ -1679,7 +1679,7 @@ public String getTranslatePlayerPlaceHolder( PlaceholderIdentifier identifier )
if ( placeHolder == PrisonPlaceHolders.prison_pbtf ||
placeHolder == PrisonPlaceHolders.prison_player_blocks_total_formatted ) {
- DecimalFormat iFmt = new DecimalFormat("#,##0");
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
results = iFmt.format( blocksTotal );
}
else {
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/RankManager.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/RankManager.java
index 71db7695a..bc452b694 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/RankManager.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/managers/RankManager.java
@@ -24,6 +24,7 @@
import java.util.Optional;
import java.util.TreeMap;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.PrisonAPI;
import tech.mcprison.prison.integration.EconomyCurrencyIntegration;
import tech.mcprison.prison.internal.CommandSender;
@@ -679,7 +680,7 @@ private String getRankCost( Rank rank, PlaceholderAttributeNumberFormat attribut
double cost = rank.getRawRankCost();
String resultsx = null;
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
if ( attributeNFormat != null ) {
resultsx = attributeNFormat.format( cost );
}
@@ -720,7 +721,7 @@ public String getTranslateRanksPlaceHolder( PlaceholderIdentifier identifier ) {
String results = null;
PrisonPlaceHolders placeHolder = placeHolderKey.getPlaceholder();
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
if ( !placeHolder.hasFlag( PlaceholderFlags.STATSPLAYERS ) &&
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index ae0268c0b..9c331678d 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -27,7 +27,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -2067,7 +2066,7 @@ public List getActiveFeatures( boolean showLaddersAndRanks ) {
if ( minesModule != null &&
minesModule.getStatus().getStatus() == ModuleStatus.Status.ENABLED ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0");
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
int minesEnabled = 0;
int minesVirtual = 0;
@@ -2964,7 +2963,7 @@ public void sellall( RankPlayer rankPlayer ) {
if ( Output.get().isDebug() ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
Output.get().logDebug( "(SpigotPlatform autosell: " + (success ? "success" : "failed") +
" ms: " + dFmt.format( milliTime ) + ") ");
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
index d6d3d7b6b..a20dc07c9 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
@@ -33,7 +33,6 @@
import tech.mcprison.prison.spigot.block.SpigotBlock;
import tech.mcprison.prison.spigot.game.SpigotPlayer;
import tech.mcprison.prison.spigot.game.SpigotWorld;
-import tech.mcprison.prison.spigot.placeholder.SpigotPlaceholders;
import tech.mcprison.prison.spigot.sellall.SellAllUtil;
import tech.mcprison.prison.util.ChatColor;
import tech.mcprison.prison.util.Location;
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
index 76983c7c1..aa760d9a2 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/AutoManagerFeatures.java
@@ -23,6 +23,7 @@
import com.cryptomorin.xseries.XMaterial;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.autofeatures.AutoFeaturesFileConfig.AutoFeatures;
import tech.mcprison.prison.cache.PlayerCache;
import tech.mcprison.prison.internal.block.PrisonBlock;
@@ -536,8 +537,8 @@ protected int autoPickup( PrisonMinesBlockBreakEvent pmEvent,
}
- DecimalFormat fFmt = new DecimalFormat("#,##0.0000");
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.0000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
double autosellTotal = 0;
double autosellUnsellableCount = 0;
@@ -1051,8 +1052,8 @@ protected void dropExtra( HashMap extra, Player player
if ( amount > 0d ) {
- DecimalFormat fFmt = new DecimalFormat("#,##0.0000");
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.0000");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
debugInfo.append( "[dropExtra sellall: value: " + dFmt.format( amount ) );
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
index b6810aedf..17f78370a 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
@@ -689,7 +689,7 @@ else if ( targetExplodedBlock.isMined() ) {
final long nanoStop = System.nanoTime();
double milliTime = (nanoStop - nanoStart) / 1000000d;
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
debugInfo.append( "(autosellBLOCKEVENTS: " + (success ? "success" : "failed") +
" ms: " + dFmt.format( milliTime ) + ") ");
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
index c32e0f0cf..46ea03910 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/commands/PrisonSpigotSellAllCommands.java
@@ -667,7 +667,7 @@ private void sellAllMultiplierCommand(CommandSender sender){
TreeMap mults = new TreeMap<>( sellAllUtil.getPrestigeMultipliers() );
// TreeMap items = new TreeMap<>( sellAllUtil.getSellAllBlocks() );
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
Set keys = mults.keySet();
@@ -941,7 +941,7 @@ private void sellAllListItems( CommandSender sender ) {
}
TreeMap items = new TreeMap<>( sellAllUtil.getSellAllBlocks() );
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
Set keys = items.keySet();
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java
index ae0f20c35..b34c0f9a8 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/economies/VaultEconomyWrapper.java
@@ -7,6 +7,7 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import net.milkbowl.vault.economy.EconomyResponse;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.Player;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.spigot.SpigotUtil;
@@ -208,7 +209,7 @@ else if (economy != null) {
results = response.transactionSuccess();
if ( !results ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
String message = String.format(
"VaultEconomy.addBalance failed: %s amount: %s " +
"balance: %s error: %s",
@@ -256,7 +257,7 @@ public boolean removeBalance(Player player, double amount) {
results = response.transactionSuccess();
if ( !results ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
String message = String.format(
"VaultEconomy.removeBalance failed: %s amount: %s " +
"balance: %s error: %s",
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotMinesGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotMinesGUI.java
index da894483c..3493c0a1e 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotMinesGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotMinesGUI.java
@@ -8,6 +8,7 @@
import com.cryptomorin.xseries.XMaterial;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.block.PrisonBlock;
import tech.mcprison.prison.mines.PrisonMines;
import tech.mcprison.prison.mines.data.Mine;
@@ -111,7 +112,7 @@ public void open(){
minesLore.addLineLoreDescription("&7" + loreBlocks);
// Init some variables and do the actions
- DecimalFormat dFmt = new DecimalFormat("##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("##0.00");
double totalChance = 0.0d;
for (PrisonBlock block : m.getPrisonBlocks()) {
@@ -159,7 +160,7 @@ public void open(){
// minesLore.addLineLoreDescription("&7" + loreBlocks);
//
// // Init some variables and do the actions
-// DecimalFormat dFmt = new DecimalFormat("##0.00");
+// DecimalFormat dFmt = Prison.get().getDecimalFormat("##0.00");
// double totalChance = 0.0d;
//
//
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
index ff6732226..73c90e668 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
@@ -10,6 +10,7 @@
import com.cryptomorin.xseries.XMaterial;
import me.clip.placeholderapi.PlaceholderAPI;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.mines.PrisonMines;
import tech.mcprison.prison.mines.data.Mine;
import tech.mcprison.prison.mines.data.PrisonSortableResults;
@@ -197,7 +198,7 @@ public void open() {
mineTag = m.getTag();
}
- DecimalFormat iFmt = new DecimalFormat( "#,##0" );
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
for (String stringValue : mineLore) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
index d0027a6e6..206570fde 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
@@ -177,8 +177,8 @@ public void open() {
boolean enchantmentEffectEnabled = getBoolean(guiConfig.getString("Options.Ranks.Enchantment_effect_current_rank"));
// Decimal Rank cost format.
- DecimalFormat formatDecimal = new DecimalFormat("###,##0.00");
- DecimalFormat mFmt = new DecimalFormat("###,##0.0000");
+ DecimalFormat formatDecimal = Prison.get().getDecimalFormat("###,##0.00");
+ DecimalFormat mFmt = Prison.get().getDecimalFormat("###,##0.0000");
boolean showNumber = getBoolean(guiConfig.getString("Options.Ranks.Number_of_Rank_Player_GUI"));
// PlayerRank pRank = rankPlayerFactory.getRank( getRankPlayer(), ladder, true );
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRankManagerGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRankManagerGUI.java
index a4e33bca8..e687ef08a 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRankManagerGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRankManagerGUI.java
@@ -6,6 +6,7 @@
import com.cryptomorin.xseries.XMaterial;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.placeholders.PlaceholdersUtil;
import tech.mcprison.prison.ranks.PrisonRanks;
import tech.mcprison.prison.ranks.data.PlayerRank;
@@ -44,7 +45,7 @@ public void open() {
ButtonLore rankupCommandsLore = new ButtonLore( guiLeftClickToOpenMsg(), null);
// Decimal Rank cost format.
- DecimalFormat formatDecimal = new DecimalFormat("###,##0.00");
+ DecimalFormat formatDecimal = Prison.get().getDecimalFormat("###,##0.00");
RankPlayerFactory rankPlayerFactory = new RankPlayerFactory();
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRanksGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRanksGUI.java
index 401771e89..cb392ec87 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRanksGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotRanksGUI.java
@@ -7,6 +7,7 @@
import com.cryptomorin.xseries.XMaterial;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.placeholders.PlaceholdersUtil;
import tech.mcprison.prison.ranks.data.Rank;
import tech.mcprison.prison.ranks.data.RankLadder;
@@ -82,7 +83,7 @@ public void open(){
String lorePlayersWithRank = guiRanksLorePlayersWithRankMsg();
// Decimal Rank cost format.
- DecimalFormat formatDecimal = new DecimalFormat("###,##0.00");
+ DecimalFormat formatDecimal = Prison.get().getDecimalFormat("###,##0.00");
// Only loop over the blocks that we need to show:
for ( Rank rank : ranksDisplay )
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
index 451737ac2..8a3c8859b 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/sellall/SellAllUtil.java
@@ -374,7 +374,7 @@ public double getPlayerMultiplier(Player p){
multiplier += multiplierExtraByPerms;
// long tPoint3 = System.nanoTime();
-// DecimalFormat dFmt = new DecimalFormat( "0.0000" );
+// DecimalFormat dFmt = Prison.get().getDecimalFormat( "0.0000" );
// String debugMsg = "{sellallMult::" + dFmt.format( multiplier ) + ":t1=" +
// dFmt.format( (tPoint2 - tPoint1)/1000000d ) +
// ":t2=" + dFmt.format( (tPoint3 - tPoint2)/1000000 ) + "}";
@@ -440,7 +440,7 @@ public double getSellMoney(Player p, HashMap xMaterialIntege
double total = earned * multiplier;
if ( debug ) {
- DecimalFormat dFmt = new DecimalFormat( "#,##0.00" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "#,##0.00" );
sb.append( " earned: " ).append( dFmt.format(earned) )
.append( " mult: " ).append( dFmt.format(multiplier) )
.append( " total: " ).append( dFmt.format(total) );
@@ -1497,7 +1497,7 @@ public void removeFromDelay(Player p){
public void removeFromAutoSellDelayAndNotify(Player p){
if (autoSellEarningsNotificationWaiting.containsKey(p) && autoSellEarningsNotificationWaiting.get(p) > 0.00){
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
String amt = fFmt.format( autoSellEarningsNotificationWaiting.get(p) );
String message = sellallAmountEarnedMsg( amt );
@@ -1805,7 +1805,7 @@ public boolean sellAllSell(Player p, boolean isUsingSign, boolean completelySile
addDelayedEarningAutoSellNotification(p, money);
} else if (notifyPlayerEarned){
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
String amt = fFmt.format( money );
String message = sellallAmountEarnedMsg( amt );
@@ -1889,7 +1889,7 @@ public double sellAllSell(Player p, SpigotItemStack itemStack,
addDelayedEarningAutoSellNotification(p, money);
}
else if (notifyPlayerEarned){
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
String amt = fFmt.format( money );
String message = sellallAmountEarnedMsg( amt ) ;
@@ -1905,7 +1905,7 @@ else if (notifyPlayerEarned){
}
-// DecimalFormat dFmt = new DecimalFormat( "0.0000" );
+// DecimalFormat dFmt = Prison.get().getDecimalFormat( "0.0000" );
// String debugMsg = "{sellAllSell::" + dFmt.format( money ) +
// ":t1=" + dFmt.format( (tPoint2 - tPoint1)/1000000d ) +
// ":t2=" + dFmt.format( (tPoint3 - tPoint2)/1000000d ) +
@@ -2018,7 +2018,7 @@ public ArrayList sellAllSell(Player p, ArrayList itemStack
addDelayedEarningAutoSellNotification(p, money);
}
} else if (notifyPlayerEarned){
- DecimalFormat fFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat fFmt = Prison.get().getDecimalFormat("#,##0.00");
String amt = fFmt.format( money );
String message = sellallAmountEarnedMsg( amt );
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventData.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventData.java
index e0601f985..39a9a92b9 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventData.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventData.java
@@ -4,6 +4,7 @@
import org.bukkit.entity.Player;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.util.Text;
public class SlimeBlockFunEventData {
@@ -23,8 +24,8 @@ public class SlimeBlockFunEventData {
private double recordBoost = 0.0;
private double recordVelocity = 0.0;
- private DecimalFormat sFmt = new DecimalFormat("#,##0.0");
- private DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ private DecimalFormat sFmt = Prison.get().getDecimalFormat("#,##0.0");
+ private DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
public SlimeBlockFunEventData( Long playerUUIDLSB, double y ) {
super();
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventListener.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventListener.java
index d90b0dd46..8b4f44971 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventListener.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/slime/SlimeBlockFunEventListener.java
@@ -16,6 +16,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.spigot.SpigotPrison;
import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
@@ -131,7 +132,7 @@ private Vector calculateVelocityY( double boost, Vector velocityOriginal, Player
if ( velocityY > 1024.0 ) {
- DecimalFormat f4Fmt = new DecimalFormat("#,##0.0000");
+ DecimalFormat f4Fmt = Prison.get().getDecimalFormat("#,##0.0000");
player.sendMessage( "SlimeFun: Exceeded max velocity!! velY:" +
f4Fmt.format( velocityY ) );
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
index aaa4ddad8..85ed85d7b 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombs.java
@@ -962,7 +962,7 @@ else if ( bomb != null ) {
mineBombsCoolDownMsg( sPlayer, cooldownTicks );
// float cooldownSeconds = cooldownTicks / 20.0f;
-// DecimalFormat dFmt = new DecimalFormat( "0.0" );
+// DecimalFormat dFmt = Prison.get().getDecimalFormat( "0.0" );
//
// String message =
// String.format( "You cannot use another Prison Mine Bomb for %s seconds.",
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsMessages.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsMessages.java
index fa86d9c53..3daf4ac78 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsMessages.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsMessages.java
@@ -2,6 +2,7 @@
import java.text.DecimalFormat;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.internal.CommandSender;
import tech.mcprison.prison.spigot.SpigotPrison;
@@ -32,7 +33,7 @@ protected String exampleReturnMsg( String mineTagName ) {
protected void mineBombsCoolDownMsg( CommandSender sender, double cooldownTicks ) {
double cooldownSeconds = cooldownTicks / 20.0f;
- DecimalFormat dFmt = new DecimalFormat( "0.0" );
+ DecimalFormat dFmt = Prison.get().getDecimalFormat( "0.0" );
SpigotPrison.getInstance().getLocaleManager()
.getLocalizable( "spigot_minebombs__cooldown_delay" )
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsTasks.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsTasks.java
index 071101d6a..a50a06d04 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsTasks.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/utils/PrisonUtilsMineBombsTasks.java
@@ -20,6 +20,7 @@
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.ParticleDisplay;
+import tech.mcprison.prison.Prison;
import tech.mcprison.prison.bombs.MineBombData;
import tech.mcprison.prison.bombs.MineBombEffectsData;
import tech.mcprison.prison.bombs.MineBombEffectsData.EffectState;
@@ -496,7 +497,7 @@ public PlacedMineBombItemTask( MineBombData bomb,
this.isDyanmicTag = bomb.getNameTag().contains( "{countdown}" );
this.tagName = "";
- this.dFmt = new DecimalFormat( "0.0" );
+ this.dFmt = Prison.get().getDecimalFormat( "0.0" );
initializeArmorStand();
}
From a307541e4653f034fcb1eaf524415da8e541dccf Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 11 Dec 2022 02:26:43 -0500
Subject: [PATCH 051/129] Setup the control over number formatting by using
Prison as the single source of constructing a DecimalFormat object. This is
done through manually setting the DecimalFormatSymbols to use en_US. It has
also been enabled in config.yml to allow setting the language code that is
used, to any value the admin may wish to use. It's a problem when en_US is
not used, but someone may have a specific reason not to use en_US. Mostly
the primary trouble is related to Minecraft not being able to properly
display NBSP unicode characters.
---
.../prison/ranks/commands/RankUpCommandMessages.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommandMessages.java b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommandMessages.java
index fe85c9513..c0782abae 100644
--- a/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommandMessages.java
+++ b/prison-ranks/src/main/java/tech/mcprison/prison/ranks/commands/RankUpCommandMessages.java
@@ -135,7 +135,7 @@ protected String prestigeConfirmationGUIMsg( CommandSender sender,
RankPlayer rPlayer, PlayerRank targetRank,
boolean isResetDefaultLadder, boolean isConfirmationEnabled ) {
StringBuilder sb = new StringBuilder();
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
String currency = targetRank.getCurrency();
double balance = rPlayer.getBalance( currency );
@@ -182,7 +182,7 @@ protected void prestigeConfirmationMsg( CommandSender sender,
RankPlayer rPlayer, PlayerRank targetRank,
boolean isResetDefaultLadder, boolean isResetMoney,
boolean isPlayer ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
String currency = targetRank.getCurrency();
double balance = rPlayer.getBalance( currency );
@@ -241,7 +241,7 @@ protected void prestigeConfirmationMsg( CommandSender sender,
protected void ranksRankupPlayerBalanceMsg( CommandSender sender,
double balance, String currency ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
LocaleManager rMsg = PrisonRanks.getInstance().getRanksMessages();
@@ -390,7 +390,7 @@ protected void ranksRankupCannotAffordMsg( CommandSender sender,
protected void ranksRankupCannotAffordMsg( CommandSender sender,
PlayerRank tpRank ) {
- DecimalFormat dFmt = new DecimalFormat("#,##0.00");
+ DecimalFormat dFmt = Prison.get().getDecimalFormat("#,##0.00");
Rank tRank = tpRank.getRank();
From 051134ff4d01accafd6eb1ffe37cf92b6569af1e Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 12 Dec 2022 03:21:31 -0500
Subject: [PATCH 052/129] Set version to v3.3.0-alpha.13f
---
docs/changelog_v3.3.x.md | 5 ++++-
gradle.properties | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 3c27dee3c..c38bd213a 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,10 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13e 2022-12-11
+# 3.3.0-alpha.13f 2022-12-12
+
+
+* **Set version to v3.3.0-alpha.13f - 2022-12-12**
* **Setup a static version of DecimalFormat which is needed to be used within all static functions.** If the DecimalFormatSymbols variable is set by a static function, then it will be replaced at the first chance by a non-static call. The static usage, if not set first by the non--static calls, cannot access the config.yml settings. This really is not a problem, since it would only be through unit tests when the gradle build is being processed that will need the alternative settings.
diff --git a/gradle.properties b/gradle.properties
index f1315c465..5d0883708 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,7 +3,7 @@
## # This is actually the "correct" place to define the version for the project.
## # Used within build.gradle with ${project.version}.
## # Can be overridden on the command line: gradle -Pversion=3.2.1-alpha.3
-version=3.3.0-alpha.13e
+version=3.3.0-alpha.13f
From d57486a2067e82f957dfbef0c305fec2bc47b0ae Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 14 Dec 2022 06:08:32 -0500
Subject: [PATCH 053/129] Enabled more detailed logging when block break events
are being ignored by the auto features. Mostly related to either the player
not holding a pickaxe, or the block has already been broke, or exploded. Now
also showing information on what the player is holding, which will help
identify why a block break event is behaving the way it is.
---
docs/changelog_v3.3.x.md | 7 +-
.../events/AutoManagerBlockBreakEvents.java | 2 +
.../events/AutoManagerCrazyEnchants.java | 2 +
.../events/AutoManagerPrisonEnchants.java | 2 +
...nagerPrisonsExplosiveBlockBreakEvents.java | 2 +
.../events/AutoManagerTokenEnchant.java | 2 +
.../events/AutoManagerZenchantments.java | 2 +
.../spigot/block/OnBlockBreakEventCore.java | 21 +++++-
.../prison/spigot/block/SpigotItemStack.java | 66 +++++++++++++++++++
.../spigot/utils/PrisonUtilsMineBombs.java | 7 +-
10 files changed, 109 insertions(+), 4 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index c38bd213a..6bf884a1e 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,12 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13f 2022-12-12
+# 3.3.0-alpha.13f 2022-12-14
+
+
+* **Enabled more detailed logging when block break events are being ignored by the auto features.**
+Mostly related to either the player not holding a pickaxe, or the block has already been broke, or exploded.
+Now also showing information on what the player is holding, which will help identify why a block break event is behaving the way it is.
* **Set version to v3.3.0-alpha.13f - 2022-12-12**
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerBlockBreakEvents.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerBlockBreakEvents.java
index 075b84026..81a5a2745 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerBlockBreakEvents.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerBlockBreakEvents.java
@@ -255,6 +255,8 @@ private void handleBlockBreakEvent( BlockBreakEvent e, BlockBreakPriority bbPrio
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
else if ( pmEvent.getBbPriority() == BlockBreakPriority.MONITOR ) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerCrazyEnchants.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerCrazyEnchants.java
index 37a587746..a3f93a5e2 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerCrazyEnchants.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerCrazyEnchants.java
@@ -268,6 +268,8 @@ public void handleBlastUseEvent( BlastUseEvent e, BlockBreakPriority bbPriority
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonEnchants.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonEnchants.java
index 8b7986bac..7646861b1 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonEnchants.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonEnchants.java
@@ -268,6 +268,8 @@ public void handlePEExplosionEvent( PEExplosionEvent e, BlockBreakPriority bbPri
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonsExplosiveBlockBreakEvents.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonsExplosiveBlockBreakEvents.java
index 2f15e72e6..cff084bf6 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonsExplosiveBlockBreakEvents.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerPrisonsExplosiveBlockBreakEvents.java
@@ -259,6 +259,8 @@ protected void handleExplosiveBlockBreakEvent( ExplosiveBlockBreakEvent e, Block
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerTokenEnchant.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerTokenEnchant.java
index 7bb9ed080..de59df5e4 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerTokenEnchant.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerTokenEnchant.java
@@ -330,6 +330,8 @@ public void handleTEBlockExplodeEvent( TEBlockExplodeEvent e, BlockBreakPriority
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
else if ( pmEvent.getBbPriority() == BlockBreakPriority.MONITOR ) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerZenchantments.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerZenchantments.java
index 7340c5eb9..c02103afc 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerZenchantments.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/AutoManagerZenchantments.java
@@ -260,6 +260,8 @@ private void handleZenchantmentsBlockBreakEvent( BlockBreakEvent e, BlockBreakPr
e.setCancelled( true );
}
+
+ debugInfo.append( "(doAction failed validation) " );
}
else if ( pmEvent.getBbPriority() == BlockBreakPriority.MONITOR ) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
index 17f78370a..ec47bec9c 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/OnBlockBreakEventCore.java
@@ -299,6 +299,12 @@ protected boolean validateEvent( PrisonMinesBlockBreakEvent pmEvent, StringBuild
debugInfo.append( sBlockHit.getLocation().toWorldCoordinates() ).append( " " );
+
+ SpigotItemStack itemInHand = pmEvent.getItemInHand();
+ debugInfo.append( "itemInHand=[" +
+ ( itemInHand == null ? "AIR" : itemInHand.getDebugInfo()) + "] ");
+
+
// Since BlastUseEvent (crazy enchant) does not identify the block that is initially
// broke, an explosion for them is greater than 1.
boolean isExplosionEvent = pmEvent.getUnprocessedRawBlocks().size() >
@@ -331,7 +337,16 @@ protected boolean validateEvent( PrisonMinesBlockBreakEvent pmEvent, StringBuild
if ( targetBlock != null &&
(targetBlock.isIgnoreAllBlockEvents() ||
targetBlock.isExploded()) ) {
- debugInfo.setLength( 0 );
+
+// debugInfo.setLength( 0 );
+ debugInfo.append( "(Primary TargetBlock forcedFastFail validateEvent [ ");
+ if ( targetBlock.isIgnoreAllBlockEvents() ) {
+ debugInfo.append( "ignoreAllBlockEvents " );
+ }
+ if ( targetBlock.isExploded() ) {
+ debugInfo.append( "alreadyExploded" );
+ }
+ debugInfo.append( "]) " );
pmEvent.setForceIfAirBlock( false );
@@ -620,7 +635,9 @@ else if ( targetExplodedBlock.isMined() ) {
pmEvent.setCancelOriginalEvent( true );
// Ignore event and clear debugInfo:
- debugInfo.setLength( 0 );
+// debugInfo.setLength( 0 );
+
+ debugInfo.append( "(TargetBlock forcedFastFail validateEvent [BlockAlreadyMined]) " );
return results;
}
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/SpigotItemStack.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/SpigotItemStack.java
index 3f7ca702b..242d50a95 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/SpigotItemStack.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/block/SpigotItemStack.java
@@ -4,9 +4,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.ItemMeta;
import com.cryptomorin.xseries.XMaterial;
@@ -17,6 +19,7 @@
import tech.mcprison.prison.internal.block.PrisonBlock;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.spigot.SpigotUtil;
+import tech.mcprison.prison.spigot.compat.SpigotCompatibility;
import tech.mcprison.prison.util.Text;
public class SpigotItemStack
@@ -428,4 +431,67 @@ public Map serialize()
return results;
}
+
+ /**
+ *
This function will return information on the item in the item stack, which is for
+ * debugging purposes, such as displayed within the autoFeatures debug info.
+ *
+ * This function is strictly for non-ops, and if a player has a given perm that
+ * is specified in the config file, then it will lock that player out of that
+ * command. This is intended to force overrides on commands for the commands
+ * that do not have their own perms.
+ *
+ * @return
+ */
+ private boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCommand,
+ String label, String[] args ) {
+ boolean results = true;
+
+ if ( !sender.isOp() ) {
+
+ // Must first check to see if the command is setup for excludes, and if
+ // not then exit with a value of true:
+ String configKey = "prisonCommandHandler.exclude-non-ops." + label.replace( " ", "." );
+ List> excludePerms = Prison.get().getPlatform().getConfigStringArray( configKey );
+
+ if ( excludePerms != null && excludePerms.size() > 0 ) {
+
+ // first check the command perms first:
+ for ( String perm : rootCommand.getPermissions() ) {
+
+ if ( sender.hasPermission( perm ) ) {
+ results = false;
+ break;
+ }
+ }
+
+ if ( results ) {
+
+ // first check the command altPerms next:
+ for ( String perm : rootCommand.getPermissions() ) {
+
+ if ( sender.hasPermission( perm ) ) {
+ results = false;
+ break;
+ }
+ }
+ }
+
+ // If results has not been set to false, then check the exclude-non-ops:
+ if ( results ) {
+
+ if ( excludePerms != null && excludePerms.size() > 0 && excludePerms.get( 0 ) instanceof String ) {
+
+ for ( Object permObj : excludePerms) {
+ if ( permObj instanceof String ) {
+ if ( sender.hasPermission( permObj.toString() ) ) {
+ results = false;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ }
+
+ // If we get to this point, and the result is true (the player has access the
+ // specified command so far), and there are more args, we need to next
+ // take the args[0] and append it to the label, and then test it again.
+ // This needs to continue until the generated command is rejected, or
+ // it passes it's clean and the player has full access to the command(s).
+ if ( results && args.length > 0 ) {
+ String newSuffix = args[0];
+ String newLabel = label + " " + newSuffix;
+ String[] newArgs = Arrays.copyOfRange( args, 1, args.length );
+
+ RegisteredCommand newSuffixCommand = rootCommand.getSuffixCommand( newSuffix );
+
+ if ( newSuffixCommand != null ) {
+
+ results = hasCommandAccess( sender, newSuffixCommand,
+ newLabel, newArgs );
+ }
+ }
+
+ return results;
+ }
+
+
public boolean onCommand(CommandSender sender, PluginCommand command, String label,
String[] args) {
@@ -757,13 +845,19 @@ public boolean onCommand(CommandSender sender, PluginCommand command, String lab
" : No root command found. " );
return false;
}
-
+
if (rootCommand.isOnlyPlayers() && !(sender instanceof Player)) {
Prison.get().getLocaleManager().getLocalizable("cantAsConsole")
.sendTo(sender, LogLevel.ERROR);
return true;
}
+ else if ( !hasCommandAccess( sender, rootCommand, label, args ) ) {
+ // The player does not have access to this command.
+ // Who cares! Just exit and do nothing. Never log this.
+ return true;
+ }
+
else {
try {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index 9c331678d..68738fcc3 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -416,6 +416,28 @@ else if ( oPlayer == null || oPlayer.getName() == null ) {
command.getUsage(),
Collections.emptyList() ) {
+ /**
+ *
This is the entry point where bukkit passes control over to prison for the
+ * commands to be executed.
+ *
+ *
+ *
This will prevent any command that a player is using from being ran in the
+ * the excluded worlds. See config.yml file and the section:
+ * `prisonCommandHandler.exclude-worlds`
+ *
+ *
+ *
There are two types of players that run commands... The primary one is
+ * an online player. Otherwise it's a CommandSender.
+ *
+ *
+ *
When the command is actually resolved and the onCommmand() is ran, the
+ * first thing it checks is to ensure that the command is not within the
+ * `prisonCommandHander.exclude-non-ops` list of commands, and if it is, then
+ * it will check all perms agains the CommandSender. The perms it checks are
+ * the perms tied to the command and the perms listed under the
+ * `prisonCommandHandler.exclude-non-ops`.
+ *
+ */
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (sender instanceof org.bukkit.entity.Player) {
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 9c9c82afb..06266ec9f 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -303,6 +303,10 @@ prisonCommandHandler:
exclude-worlds:
- lobby
- plotWorld
+ exclude-non-ops:
+ mines:
+ tp:
+ - prison.exclude.test
aliases:
mines:
tp:
From cb8da0b189daab3cb5fe112105b941895f81f014 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Sun, 25 Dec 2022 17:16:12 -0500
Subject: [PATCH 060/129] New Feature: command lockout: expanded to get this to
work for commands, help listings, and aliases. There is now a setting where
if enabled, it will expand the lockout from a command to all aliases of that
command. Also on each command, it will will allow enabling (enabled by
default) if either the command parms or parmAlts are used to exclude a player
from a command.
---
docs/changelog_v3.3.x.md | 3 +
.../prison/commands/CommandHandler.java | 159 +++++++++++-------
.../mcprison/prison/commands/HelpHandler.java | 3 +-
.../prison/commands/RegisteredCommand.java | 16 +-
.../prison/spigot/SpigotPlatform.java | 4 +-
prison-spigot/src/main/resources/config.yml | 38 ++++-
6 files changed, 157 insertions(+), 66 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 835510dd8..9cfbfcd48 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13f 2022-12-23
+* **New Feature: command lockout:** expanded to get this to work for commands, help listings, and aliases. There is now a setting where if enabled, it will expand the lockout from a command to all aliases of that command. Also on each command, it will will allow enabling (enabled by default) if either the command parms or parmAlts are used to exclude a player from a command.
+
+
* **New feature: command lockout for users based upon perms set in the config.yml.**
This is the first stage of getting this setup, where it locks out the running of a command.
Need to lockout the help next, which is what generates the command lists.
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
index 8f98b30a2..2edf28650 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
@@ -136,7 +136,11 @@ private String formatArgument(CommandArgument argument) {
}
@Override
- public ChatDisplay getHelpMessage(RegisteredCommand command) {
+ public ChatDisplay getHelpMessage(CommandSender sender, RegisteredCommand command) {
+
+ if ( !hasCommandAccess(sender, command, command.getLabel(), new String[0] ) ) {
+ return null;
+ }
ChatDisplay chatDisplay = new ChatDisplay(
String.format( "Cmd: &7%s",
@@ -253,24 +257,36 @@ public ChatDisplay getHelpMessage(RegisteredCommand command) {
List subcommands = command.getSuffixes();
if (subcommands.size() > 0) {
- chatDisplay.addText(ChatColor.DARK_AQUA + "Subcommands:");
+
// Force a sorting by use of a TreeSet. Collections.sort() would not work.
TreeSet subCommandSet = new TreeSet<>();
for (RegisteredCommand scommand : subcommands) {
- String subCmd = scommand.getUsage();
-
- int subCmdSubCnt = scommand.getSuffixes().size();
- String subCommands = (subCmdSubCnt == 0 ? "" :
- ChatColor.DARK_AQUA + "(" + subCmdSubCnt + " Subcommands)");
- String isAlias = scommand.isAlias() ? ChatColor.DARK_AQUA + " Alias" : "";
+ String sLabel = scommand.getCompleteLabel();
+
+ if ( hasCommandAccess(sender, scommand, sLabel, new String[0] ) ) {
+
+ String subCmd = scommand.getUsage();
+
+ int subCmdSubCnt = scommand.getSuffixes().size();
+ String subCommands = (subCmdSubCnt == 0 ? "" :
+ ChatColor.DARK_AQUA + "(" + subCmdSubCnt + " Subcommands)");
+
+ String isAlias = scommand.isAlias() ? ChatColor.DARK_AQUA + " Alias" : "";
+
+ subCommandSet.add(
+ String.format( "%s %s %s", subCmd, subCommands, isAlias ));
+ }
- subCommandSet.add(
- String.format( "%s %s %s", subCmd, subCommands, isAlias ));
}
-
- for (String subCmd : subCommandSet) {
- chatDisplay.addText(subCmd);
+
+ // Only if there are entries to show, then include the header and the details
+ if ( subCommandSet.size() > 0 ) {
+ chatDisplay.addText(ChatColor.DARK_AQUA + "Subcommands:");
+
+ for (String subCmd : subCommandSet) {
+ chatDisplay.addText(subCmd);
+ }
}
}
@@ -758,58 +774,25 @@ public static String[] addConfigAliases( String label, String[] aliases )
*
* @return
*/
- private boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCommand,
+ public boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCommand,
String label, String[] args ) {
boolean results = true;
if ( !sender.isOp() ) {
- // Must first check to see if the command is setup for excludes, and if
- // not then exit with a value of true:
- String configKey = "prisonCommandHandler.exclude-non-ops." + label.replace( " ", "." );
- List> excludePerms = Prison.get().getPlatform().getConfigStringArray( configKey );
+ String exRAKey = "prisonCommandHandler.exclude-non-ops.exclude-related-aliases";
+ boolean excludeRelatedAliases = getConfigBoolean( exRAKey );
+
+ String sLabelAlias = !excludeRelatedAliases || rootCommand.getParentOfAlias() == null ?
+ null : rootCommand.getParentOfAlias().getCompleteLabel();
+
+
+ results = commandAccessPermChecks(sender, rootCommand, label, results);
- if ( excludePerms != null && excludePerms.size() > 0 ) {
+ if ( results && sLabelAlias != null ) {
- // first check the command perms first:
- for ( String perm : rootCommand.getPermissions() ) {
-
- if ( sender.hasPermission( perm ) ) {
- results = false;
- break;
- }
- }
-
- if ( results ) {
-
- // first check the command altPerms next:
- for ( String perm : rootCommand.getPermissions() ) {
-
- if ( sender.hasPermission( perm ) ) {
- results = false;
- break;
- }
- }
- }
-
- // If results has not been set to false, then check the exclude-non-ops:
- if ( results ) {
-
- if ( excludePerms != null && excludePerms.size() > 0 && excludePerms.get( 0 ) instanceof String ) {
-
- for ( Object permObj : excludePerms) {
- if ( permObj instanceof String ) {
- if ( sender.hasPermission( permObj.toString() ) ) {
- results = false;
- break;
- }
- }
- }
- }
-
- }
+ results = commandAccessPermChecks(sender, rootCommand.getParentOfAlias(), sLabelAlias, results);
}
-
}
@@ -835,6 +818,68 @@ private boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCo
return results;
}
+ private boolean commandAccessPermChecks(CommandSender sender, RegisteredCommand rootCommand, String label,
+ boolean results) {
+ // Must first check to see if the command is setup for excludes, and if
+ // not then exit with a value of true:
+ String configKey = "prisonCommandHandler.exclude-non-ops.commands" +
+ label.replace( " ", "." );
+ List> excludePerms = getConfigStringArray( configKey + ".perms" );
+ boolean includeCommandPerms = getConfigBoolean( configKey + ".includeCmdPerms" );
+ boolean includeCommandAltPerms = getConfigBoolean( configKey + ".includeCmdAltPerms" );
+
+ if ( excludePerms != null && excludePerms.size() > 0 ) {
+
+ // first check the command perms first:
+ if ( includeCommandPerms ) {
+
+ for ( String perm : rootCommand.getPermissions() ) {
+
+ if ( sender.hasPermission( perm ) ) {
+ results = false;
+ break;
+ }
+ }
+ }
+
+ if ( results && includeCommandAltPerms ) {
+
+ // first check the command altPerms next:
+ for ( String perm : rootCommand.getPermissions() ) {
+
+ if ( sender.hasPermission( perm ) ) {
+ results = false;
+ break;
+ }
+ }
+ }
+
+ // If results has not been set to false, then check the exclude-non-ops:
+ if ( results ) {
+
+ if ( excludePerms != null && excludePerms.size() > 0 && excludePerms.get( 0 ) instanceof String ) {
+
+ for ( Object permObj : excludePerms) {
+ if ( permObj instanceof String ) {
+ if ( sender.hasPermission( permObj.toString() ) ) {
+ results = false;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ return results;
+ }
+
+ private boolean getConfigBoolean( String configKey ) {
+ return Prison.get().getPlatform().getConfigBooleanFalse( configKey );
+ }
+ private List> getConfigStringArray( String configKey ) {
+ return Prison.get().getPlatform().getConfigStringArray( configKey );
+ }
public boolean onCommand(CommandSender sender, PluginCommand command, String label,
String[] args) {
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/HelpHandler.java b/prison-core/src/main/java/tech/mcprison/prison/commands/HelpHandler.java
index 525562117..6d2038c31 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/HelpHandler.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/HelpHandler.java
@@ -18,11 +18,12 @@
package tech.mcprison.prison.commands;
+import tech.mcprison.prison.internal.CommandSender;
import tech.mcprison.prison.output.ChatDisplay;
public interface HelpHandler {
- public ChatDisplay getHelpMessage(RegisteredCommand command);
+ public ChatDisplay getHelpMessage(CommandSender sender, RegisteredCommand command);
public String getUsageNoParameters(RegisteredCommand command);
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
index 4e36bceee..fcd3fb65b 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
@@ -154,6 +154,12 @@ public String getCompleteLabel() {
* @param args
*/
void execute(CommandSender sender, String[] args) {
+
+ // First ensure the player is not locked out of this command:
+ if ( !handler.hasCommandAccess(sender, this, getLabel(), args) ) {
+ return;
+ }
+
if (!testPermission(sender)) {
Prison.get().getLocaleManager().getLocalizable("noPermission")
.sendTo(sender, LogLevel.ERROR);
@@ -304,8 +310,8 @@ public List getFlags() {
return flags;
}
- public ChatDisplay getHelpMessage() {
- return handler.getHelpHandler().getHelpMessage(this);
+ public ChatDisplay getHelpMessage( CommandSender sender ) {
+ return handler.getHelpHandler().getHelpMessage( sender, this );
}
public String getLabel() {
@@ -387,7 +393,11 @@ public boolean isSet() {
public void sendHelpMessage(CommandSender sender) {
- getHelpMessage().send( sender );
+ ChatDisplay chatDisp = getHelpMessage( sender );
+
+ if ( chatDisp != null ) {
+ chatDisp.send( sender );
+ }
}
void set(Object methodInstance, Method method) {
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
index 68738fcc3..83effff6d 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPlatform.java
@@ -432,10 +432,10 @@ else if ( oPlayer == null || oPlayer.getName() == null ) {
*
*
When the command is actually resolved and the onCommmand() is ran, the
* first thing it checks is to ensure that the command is not within the
- * `prisonCommandHander.exclude-non-ops` list of commands, and if it is, then
+ * `prisonCommandHander.exclude-non-ops.commands` list of commands, and if it is, then
* it will check all perms agains the CommandSender. The perms it checks are
* the perms tied to the command and the perms listed under the
- * `prisonCommandHandler.exclude-non-ops`.
+ * `prisonCommandHandler.exclude-non-ops.commands`.
*
*/
@Override
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index 06266ec9f..ad26acb8a 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -299,14 +299,46 @@ prison-events:
priority: LOW
+
+# The prisonCommandHander allows you to fine tune the Prison Command Handler
+# by adding aliases for any command, prevent non-op players from using specific
+# commands, viewing the command's' help, or list the blocked commands.
+#
+# Commands must be listed in a hierarchy format. For example the command
+# `/mines tp` must be listed under the appropreiate sections as:
+# mines:
+# tp:
+#
+# For the exclude-non-ops there is a global setting that will apply the
+# restriction to specified command, plus their aliases. If set to false,
+# then each alias would have to be listed for them to be excluded.
+#
+# For each exclude-non-ops entry, you can specify the includeCmdPerms and
+# the includeCmdAltPerms, both of which defaults to true. You would have
+# to explicity negate them to prevent them from applying.
+# For the includeCmdPerms, all perms included in the command are tested for
+# each player, and if there is a hit then the command is excluded for that player.
+# For the includeCmdAltPerms all are tested too, but no translations are
+# applied so most may not produce any hits.
+# The listed perms for each command are tested as is, with no translations.
+# If the given player has a hit on the perm, then they are excluded from
+# being able to use the command.
+#
+# OPs, including console, are bypassed and cannot be excluded from any command.
+#
prisonCommandHandler:
exclude-worlds:
- lobby
- plotWorld
exclude-non-ops:
- mines:
- tp:
- - prison.exclude.test
+ exclude-related-aliases: true
+ commands:
+ mines:
+ tp:
+ includeCmdPerms: true
+ includeCmdAltPerms: true
+ perms:
+ - prison.exclude.test
aliases:
mines:
tp:
From 4796a61f57a5b0799d33de186627a86b9b010683 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Mon, 26 Dec 2022 00:21:17 -0500
Subject: [PATCH 061/129] New Feature: command lockout: Updated to add
debugging information to identify why a command is rejected for a player
through logging in the console when prison is in debug mode.
---
docs/changelog_v3.3.x.md | 5 +-
.../prison/commands/CommandAccessResults.java | 107 ++++++++++++++++++
.../prison/commands/CommandHandler.java | 59 ++++++----
3 files changed, 151 insertions(+), 20 deletions(-)
create mode 100644 prison-core/src/main/java/tech/mcprison/prison/commands/CommandAccessResults.java
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 9cfbfcd48..98337c273 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,10 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13f 2022-12-23
+# 3.3.0-alpha.13f 2022-12-26
+
+
+* **New Feature: command lockout:** Updated to add debugging information to identify why a command is rejected for a player through logging in the console when prison is in debug mode.
* **New Feature: command lockout:** expanded to get this to work for commands, help listings, and aliases. There is now a setting where if enabled, it will expand the lockout from a command to all aliases of that command. Also on each command, it will will allow enabling (enabled by default) if either the command parms or parmAlts are used to exclude a player from a command.
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandAccessResults.java b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandAccessResults.java
new file mode 100644
index 000000000..46a8f7bc5
--- /dev/null
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandAccessResults.java
@@ -0,0 +1,107 @@
+package tech.mcprison.prison.commands;
+
+import tech.mcprison.prison.internal.CommandSender;
+import tech.mcprison.prison.output.Output;
+
+public class CommandAccessResults {
+
+ private CommandSender sender;
+
+ private String command;
+ private String perm;
+
+ private boolean access = true;
+
+ private CommandAccessRejectionReason rejectionReason;
+
+ public enum CommandAccessRejectionReason {
+ UNKNOWN__NOT_CHECKED,
+ ACCESS_PERMITTED,
+
+ REJECTION__COMMAND_PERMISSIONS,
+ REJECTION__COMMAND_ALT_PERMISSIONS,
+ REJECTION__CONFIG_YAML;
+ }
+
+ public CommandAccessResults( CommandSender sender ) {
+ super();
+
+ this.sender = sender;
+ this.perm = "";
+
+ this.access = true;
+ this.rejectionReason = CommandAccessRejectionReason.UNKNOWN__NOT_CHECKED;
+ }
+
+ public void setAccessPermitted() {
+ setAccess( true );
+ setRejectionReason( CommandAccessRejectionReason.ACCESS_PERMITTED);
+ }
+ public void rejectCommandPermission( String command, String perm ) {
+ setCommand( command );
+ setPerm( perm );
+ setAccess( false );
+ setRejectionReason( CommandAccessRejectionReason.REJECTION__COMMAND_PERMISSIONS);
+ }
+ public void rejectCommandAltPermission( String command, String perm ) {
+ setCommand( command );
+ setPerm( perm );
+ setAccess( false );
+ setRejectionReason( CommandAccessRejectionReason.REJECTION__COMMAND_ALT_PERMISSIONS);
+ }
+ public void rejectConfigYaml( String command, String perm ) {
+ setCommand( command );
+ setPerm( perm );
+ setAccess( false );
+ setRejectionReason( CommandAccessRejectionReason.REJECTION__CONFIG_YAML);
+ }
+
+ public void debugAccess() {
+ if ( Output.get().isDebug() ) {
+ String msg = String.format( "Command Access for %s: %b [%s] Perm: [%s] Reason: %s]",
+ getSender().getName(),
+ isAccess(),
+ getCommand() == null ? "" : getCommand(),
+ getPerm() == null ? "" : getPerm(),
+ getRejectionReason().name()
+ );
+
+ Output.get().logInfo( msg );
+ }
+ }
+
+ public CommandSender getSender() {
+ return sender;
+ }
+ public void setSender(CommandSender sender) {
+ this.sender = sender;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
+ public String getPerm() {
+ return perm;
+ }
+ public void setPerm(String perm) {
+ this.perm = perm;
+ }
+
+ public boolean isAccess() {
+ return access;
+ }
+ public void setAccess(boolean access) {
+ this.access = access;
+ }
+
+ public CommandAccessRejectionReason getRejectionReason() {
+ return rejectionReason;
+ }
+ public void setRejectionReason(CommandAccessRejectionReason rejectionReason) {
+ this.rejectionReason = rejectionReason;
+ }
+}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
index 2edf28650..6e0952ef9 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
@@ -776,7 +776,28 @@ public static String[] addConfigAliases( String label, String[] aliases )
*/
public boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCommand,
String label, String[] args ) {
- boolean results = true;
+
+ CommandAccessResults results = new CommandAccessResults( sender );
+
+ hasCommandAccess( sender, rootCommand, label, args, results );
+
+ if ( results.isAccess() ) {
+ results.setAccessPermitted();
+ }
+
+ if ( !results.isAccess() ) {
+ // Debug logging if prison is in debug mode:
+ results.debugAccess();
+ }
+
+ return results.isAccess();
+ }
+
+ private void hasCommandAccess( CommandSender sender, RegisteredCommand rootCommand,
+ String label, String[] args,
+ CommandAccessResults results ) {
+
+// boolean results = true;
if ( !sender.isOp() ) {
@@ -787,11 +808,11 @@ public boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCom
null : rootCommand.getParentOfAlias().getCompleteLabel();
- results = commandAccessPermChecks(sender, rootCommand, label, results);
+ commandAccessPermChecks( sender, rootCommand, label, results );
- if ( results && sLabelAlias != null ) {
+ if ( results.isAccess() && sLabelAlias != null ) {
- results = commandAccessPermChecks(sender, rootCommand.getParentOfAlias(), sLabelAlias, results);
+ commandAccessPermChecks( sender, rootCommand.getParentOfAlias(), sLabelAlias, results );
}
}
@@ -801,7 +822,7 @@ public boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCom
// take the args[0] and append it to the label, and then test it again.
// This needs to continue until the generated command is rejected, or
// it passes it's clean and the player has full access to the command(s).
- if ( results && args.length > 0 ) {
+ if ( results.isAccess() && args.length > 0 ) {
String newSuffix = args[0];
String newLabel = label + " " + newSuffix;
String[] newArgs = Arrays.copyOfRange( args, 1, args.length );
@@ -810,20 +831,21 @@ public boolean hasCommandAccess( CommandSender sender, RegisteredCommand rootCom
if ( newSuffixCommand != null ) {
- results = hasCommandAccess( sender, newSuffixCommand,
- newLabel, newArgs );
+ hasCommandAccess( sender, newSuffixCommand,
+ newLabel, newArgs, results );
}
}
- return results;
}
- private boolean commandAccessPermChecks(CommandSender sender, RegisteredCommand rootCommand, String label,
- boolean results) {
+ private void commandAccessPermChecks(CommandSender sender, RegisteredCommand rootCommand, String label,
+ CommandAccessResults results) {
+
// Must first check to see if the command is setup for excludes, and if
// not then exit with a value of true:
- String configKey = "prisonCommandHandler.exclude-non-ops.commands" +
+ String configKey = "prisonCommandHandler.exclude-non-ops.commands." +
label.replace( " ", "." );
+
List> excludePerms = getConfigStringArray( configKey + ".perms" );
boolean includeCommandPerms = getConfigBoolean( configKey + ".includeCmdPerms" );
boolean includeCommandAltPerms = getConfigBoolean( configKey + ".includeCmdAltPerms" );
@@ -836,33 +858,33 @@ private boolean commandAccessPermChecks(CommandSender sender, RegisteredCommand
for ( String perm : rootCommand.getPermissions() ) {
if ( sender.hasPermission( perm ) ) {
- results = false;
+ results.rejectCommandPermission( label, perm );
break;
}
}
}
- if ( results && includeCommandAltPerms ) {
+ if ( results.isAccess() && includeCommandAltPerms ) {
// first check the command altPerms next:
- for ( String perm : rootCommand.getPermissions() ) {
+ for ( String altPerm : rootCommand.getAltPermissions() ) {
- if ( sender.hasPermission( perm ) ) {
- results = false;
+ if ( sender.hasPermission( altPerm ) ) {
+ results.rejectCommandAltPermission( label, altPerm );
break;
}
}
}
// If results has not been set to false, then check the exclude-non-ops:
- if ( results ) {
+ if ( results.isAccess() ) {
if ( excludePerms != null && excludePerms.size() > 0 && excludePerms.get( 0 ) instanceof String ) {
for ( Object permObj : excludePerms) {
if ( permObj instanceof String ) {
if ( sender.hasPermission( permObj.toString() ) ) {
- results = false;
+ results.rejectConfigYaml( label, permObj.toString() );
break;
}
}
@@ -871,7 +893,6 @@ private boolean commandAccessPermChecks(CommandSender sender, RegisteredCommand
}
}
- return results;
}
private boolean getConfigBoolean( String configKey ) {
From fe088020f1ae7af353060620d2ddba4727e65548 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 28 Dec 2022 03:26:38 -0500
Subject: [PATCH 062/129] Player GUI for mines and ranks was changed to include
within the NBT codes, and enabled the mines TP command to be set in the NBT
command tag. This will allow the NBT handler within the
SpigotGUIMenuTools.processGUIPage(), of which it would just run the supplied
command. This bypasses the need of using special code to extract the mine
name or rank name to reconstruct a command. In short, this allows the TP On
Click action to be self contained without the need for special handlers. This
is a fix for the fully customizable ranks and mines GUI menus for the
players, where the mine name on lore line 1 was eliminated, and hence the old
way was unable to identify what mine should initiate the tp event. But
having the plain mine name on line one resulted in multiple redundancies of
the mine's name, along with the mine's tag and the item's header.
---
docs/changelog_v3.3.x.md | 7 ++++++-
.../prison/spigot/gui/SpigotGUIMenuTools.java | 3 +++
.../spigot/gui/mine/SpigotPlayerMinesGUI.java | 20 ++++++++++++++++++-
.../spigot/gui/rank/SpigotPlayerRanksGUI.java | 9 +++++++++
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 98337c273..28c8167d0 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,12 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13f 2022-12-26
+# 3.3.0-alpha.13f 2022-12-28
+
+
+* **Player GUI for mines and ranks was changed to include within the NBT codes, and enabled the mines TP command to be set in the NBT command tag.**
+This will allow the NBT handler within the SpigotGUIMenuTools.processGUIPage(), of which it would just run the supplied command. This bypasses the need of using special code to extract the mine name or rank name to reconstruct a command. In short, this allows the TP On Click action to be self contained without the need for special handlers.
+This is a fix for the fully customizable ranks and mines GUI menus for the players, where the mine name on lore line 1 was eliminated, and hence the old way was unable to identify what mine should initiate the tp event. But having the plain mine name on line one resulted in multiple redundancies of the mine's name, along with the mine's tag and the item's header.
* **New Feature: command lockout:** Updated to add debugging information to identify why a command is rejected for a player through logging in the console when prison is in debug mode.
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/SpigotGUIMenuTools.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/SpigotGUIMenuTools.java
index 7067f1439..e5279fe08 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/SpigotGUIMenuTools.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/SpigotGUIMenuTools.java
@@ -27,6 +27,9 @@ public class SpigotGUIMenuTools
public static final String GUI_MENU_TOOLS_NBT_ENABLED = "guiNBT";
public static final String GUI_MENU_TOOLS_NBT_COMMAND = "guiNBTCommand";
+
+ public static final String GUI_MENU_TOOLS_NBT_RANK_NAME = "guiNBTRankName";
+ public static final String GUI_MENU_TOOLS_NBT_MINE_NAME = "guiNBTMineName";
private static SpigotGUIMenuTools instance;
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
index 5015f12fb..9b4b6015b 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/mine/SpigotPlayerMinesGUI.java
@@ -9,6 +9,7 @@
import com.cryptomorin.xseries.XMaterial;
+import de.tr7zw.nbtapi.NBTItem;
import me.clip.placeholderapi.PlaceholderAPI;
import tech.mcprison.prison.Prison;
import tech.mcprison.prison.mines.PrisonMines;
@@ -25,6 +26,7 @@
import tech.mcprison.prison.spigot.gui.guiutility.ButtonLore;
import tech.mcprison.prison.spigot.gui.guiutility.PrisonGUI;
import tech.mcprison.prison.spigot.gui.rank.SpigotGUIMessages;
+import tech.mcprison.prison.spigot.nbt.PrisonNBTUtil;
import tech.mcprison.prison.util.Text;
/**
@@ -244,10 +246,26 @@ public void open() {
minesLore.setLoreAction( lores );
}
+
+
+ Button itemMine = new Button(null, xMat, minesLore, "&3" + mineTag);
+
+ String mineTeleportCommand =
+ Output.stringFormat(
+ "mines teleport %s %s",
+ m.getName(),
+ p.getName() );
+ // Before adding the button, add an NBT tag for the command and rank name:
+ PrisonNBTUtil nbtUtil = new PrisonNBTUtil();
+ NBTItem nbtItem = nbtUtil == null ? null : nbtUtil.getNBT( itemMine.getButtonItem());
+ nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_ENABLED, "true");
+ nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_COMMAND, mineTeleportCommand );
+ nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_MINE_NAME, m.getName() );
+
// Add the button to the inventory.
- gui.addButton(new Button(null, xMat, minesLore, "&3" + mineTag));
+ gui.addButton( itemMine );
// String mineTag = m.getTag();
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
index 74c2a447c..d59b2aec3 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/gui/rank/SpigotPlayerRanksGUI.java
@@ -266,6 +266,15 @@ public void open() {
}
}
+
+ // Before adding the button, add an NBT tag for the command and rank name:
+ PrisonNBTUtil nbtUtil = new PrisonNBTUtil();
+ NBTItem nbtItem = nbtUtil == null ? null : nbtUtil.getNBT( itemRank.getButtonItem());
+ nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_ENABLED, "true");
+// nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_COMMAND, noCommmand );
+ nbtUtil.setNBTString(nbtItem, SpigotGUIMenuTools.GUI_MENU_TOOLS_NBT_RANK_NAME, rank.getName() );
+
+
gui.addButton(itemRank);
// rank = rank.getRankNext();
From 17092da7e6bde720c827d9f6f0c288288e823a39 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 28 Dec 2022 03:28:19 -0500
Subject: [PATCH 063/129] Fixed a typo in the config.yml that covered what the
default values were for the includeCmdAltPerms and includeCmdPerms settings.
---
docs/changelog_v3.3.x.md | 3 +++
prison-spigot/src/main/resources/config.yml | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 28c8167d0..ddb1a4616 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,9 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13f 2022-12-28
+* **Fixed a typo in the config.yml that covered what the default values were for the includeCmdAltPerms and includeCmdPerms settings.**
+
+
* **Player GUI for mines and ranks was changed to include within the NBT codes, and enabled the mines TP command to be set in the NBT command tag.**
This will allow the NBT handler within the SpigotGUIMenuTools.processGUIPage(), of which it would just run the supplied command. This bypasses the need of using special code to extract the mine name or rank name to reconstruct a command. In short, this allows the TP On Click action to be self contained without the need for special handlers.
This is a fix for the fully customizable ranks and mines GUI menus for the players, where the mine name on lore line 1 was eliminated, and hence the old way was unable to identify what mine should initiate the tp event. But having the plain mine name on line one resulted in multiple redundancies of the mine's name, along with the mine's tag and the item's header.
diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml
index ad26acb8a..8ab842c72 100644
--- a/prison-spigot/src/main/resources/config.yml
+++ b/prison-spigot/src/main/resources/config.yml
@@ -314,8 +314,9 @@ prison-events:
# then each alias would have to be listed for them to be excluded.
#
# For each exclude-non-ops entry, you can specify the includeCmdPerms and
-# the includeCmdAltPerms, both of which defaults to true. You would have
-# to explicity negate them to prevent them from applying.
+# the includeCmdAltPerms, both of which defaults to false. You would have
+# to explicity enable them to prevent them from applying; use a value of true.
+#
# For the includeCmdPerms, all perms included in the command are tested for
# each player, and if there is a hit then the command is excluded for that player.
# For the includeCmdAltPerms all are tested too, but no translations are
From fa0bce134f75f9d43ed2a4fe8b3e09cfa087cd2c Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 28 Dec 2022 04:34:57 -0500
Subject: [PATCH 064/129] There is a growing problem with the use of % symbols
being processed multiple times with the Java String.format() which results in
format escape error. First, the use of Output is new setup to handle it's own
custom version of String.formatIO that will take any remaining percent symbol
and encode it so it does not cause errors anymore, then right before passing
it to bukkit, it will convert it back. This allows it to pass through as
many String.format() functions as needed without resulting in to any
problems. The other fix, which is probably more significant, is that the
Output functions no longer tries to run all messages through String.format()
if there are no parameters to apply. This was causing the most issues. To
properly ensure the more complex message handling works correctly, the use of
Output.stringFormat(() should be use to enable to the encoding of the percent
symbols.
---
docs/changelog_v3.3.x.md | 6 +++
.../tech/mcprison/prison/output/Output.java | 46 ++++++++++++++++++-
.../prison/spigot/nbt/PrisonNBTUtil.java | 35 ++++++++++++--
3 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index ddb1a4616..89cb74a1d 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,12 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13f 2022-12-28
+* **There is a growing problem with the use of % symbols being processed multiple times with the Java String.format() which results in format escape error.**
+First, the use of Output is new setup to handle it's own custom version of String.formatIO that will take any remaining percent symbol and encode it so it does not cause errors anymore, then right before passing it to bukkit, it will convert it back. This allows it to pass through as many String.format() functions as needed without resulting in to any problems.
+The other fix, which is probably more significant, is that the Output functions no longer tries to run all messages through String.format() if there are no parameters to apply. This was causing the most issues.
+To properly ensure the more complex message handling works correctly, the use of Output.stringFormat(() should be use to enable to the encoding of the percent symbols.
+
+
* **Fixed a typo in the config.yml that covered what the default values were for the includeCmdAltPerms and includeCmdPerms settings.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/output/Output.java b/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
index 871b2cd92..0dd5171d4 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
@@ -37,6 +37,9 @@
*/
public class Output
extends OutputMessages {
+
+ public static final String PERCENT_ENCODING = "%";
+ public static final String PERCENT_DECODING = "%";
private static Output instance;
@@ -201,6 +204,38 @@ public String format(String message, LogLevel level, Object... args) {
return getLogPrefix(level) + String.format(message, args);
}
+ /**
+ *
This version of String format should be used in place of the standard
+ * Java String.format() function since if there is a percent remaining in
+ * the results, it will then encode it so it does not trigger a Java
+ * format error where it thinks the % is an escape character for the
+ * the String.format() command. This class, when actually logging the
+ * message, will convert the encoded percent back to a normal percent.
+ *
+ *
+ *
This is a potential problem due to the number of times one message
+ * may be passed through a String.format(). This prevents a properly
+ * escaped percent, of `%%` from being a single percent to be used as
+ * a encoded escape for formatting.
+ *
This class manages the use of NBTs within prison so it's a common interface
+ * that is consistent and works properly.
+ *
+ *
+ *
This class has debug logging, but by default it is turned off to keep it from
+ * getting to be too verbose in the logs. The idea is that once a section of code
+ * is working then it does not need to have debugging enabled. So this is used
+ * more for testing new sections of code.
+ *
+ *
+ * @author Blue
+ *
+ */
public class PrisonNBTUtil {
+ private boolean enableDebugLogging = false;
public NBTItem getNBT( ItemStack bukkitStack ) {
NBTItem nbtItemStack = null;
@@ -16,7 +31,10 @@ public NBTItem getNBT( ItemStack bukkitStack ) {
try {
nbtItemStack = new NBTItem( bukkitStack, true );
- nbtDebugLog( nbtItemStack, "getNbt" );
+ if ( isEnableDebugLogging() ) {
+ nbtDebugLog( nbtItemStack, "getNbt" );
+ }
+
} catch (Exception e) {
// ignore - the bukkit item stack is not compatible with the NBT library
}
@@ -32,7 +50,7 @@ private void nbtDebugLog( NBTItem nbtItem, String desc ) {
int sysId = System.identityHashCode(iStack);
- String message = String.format(
+ String message = Output.stringFormat(
"NBT %s ItemStack for %s: %s sysId: %d",
desc,
iStack.hasItemMeta() && iStack.getItemMeta().hasDisplayName() ?
@@ -72,8 +90,19 @@ public void setNBTString( NBTItem nbtItem, String key, String value ) {
if ( nbtItem != null ) {
nbtItem.setString( key, value );
- nbtDebugLog( nbtItem, "setNBTString" );
+
+ if ( isEnableDebugLogging() ) {
+ nbtDebugLog( nbtItem, "setNBTString" );
+ }
}
}
+
+
+ public boolean isEnableDebugLogging() {
+ return enableDebugLogging;
+ }
+ public void setEnableDebugLogging(boolean enableDebugLogging) {
+ this.enableDebugLogging = enableDebugLogging;
+ }
}
From 9d7cd985db940ccfa2be6cdbd3be623e2dd319dc Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 28 Dec 2022 13:08:52 -0500
Subject: [PATCH 065/129] Added Finnish translations to prison! Thearex12
contributed a number of Finnish translations for prison in the following
modules: core (partial), mines, and sellall. More updates are in progress.
---
docs/changelog_v3.3.x.md | 7 +
.../main/resources/lang/core/fi_FI.properties | 185 ++++++++++++++++++
.../resources/lang/mines/fi_FI.properties | 99 ++++++++++
.../resources/lang/sellall/fi_FI.properties | 67 +++++++
4 files changed, 358 insertions(+)
create mode 100644 prison-core/src/main/resources/lang/core/fi_FI.properties
create mode 100644 prison-core/src/main/resources/lang/mines/fi_FI.properties
create mode 100644 prison-core/src/main/resources/lang/sellall/fi_FI.properties
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 89cb74a1d..f87c6b93b 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,6 +12,13 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13f 2022-12-28
+* **Added Finnish translations to prison!**
+Thearex12 contributed a number of Finnish translations for prison in the following
+modules: core (partial), mines, and sellall. More updates are in progress.
+If anyone else would like to contribute another translation, please ping me,
+RoyalBlueRanger, on our discord server. It can be a complete translation, or
+a partial. Thanks!
+
* **There is a growing problem with the use of % symbols being processed multiple times with the Java String.format() which results in format escape error.**
First, the use of Output is new setup to handle it's own custom version of String.formatIO that will take any remaining percent symbol and encode it so it does not cause errors anymore, then right before passing it to bukkit, it will convert it back. This allows it to pass through as many String.format() functions as needed without resulting in to any problems.
diff --git a/prison-core/src/main/resources/lang/core/fi_FI.properties b/prison-core/src/main/resources/lang/core/fi_FI.properties
new file mode 100644
index 000000000..424e2488a
--- /dev/null
+++ b/prison-core/src/main/resources/lang/core/fi_FI.properties
@@ -0,0 +1,185 @@
+#
+# Prison is a Minecraft plugin for the prison game mode.
+# Copyright (C) 2021 The Prison Team
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+
+##
+## Prison Supports Unicode (UTF-8) encoding in these properties files. BUt you must
+## follow these instructions to ensure everything works properly.
+##
+## 1. You should only edit these files using a UTF-8 editor. On windows use NotePad, not WordPad.
+## WordPad will save as plain text. To confirm the save was successful: save, close the editor,
+## then reopen to confirm the encoding was preserved.
+##
+## 2. When running on Windows, you must enable utf-8 encoding in minecraft's console. Windows
+## defaults to a characterpage 1252. To enable window's use of utf-8, you need to change the
+## encoding prior to launching spigot/paper:
+## chcp 65001
+##
+## Full example of a windows script, which hooks for java debugging:
+## rem Note: chcp 65001 enables utf-8 in windows, when normally windows uses characterpage 1252
+## chcp 65001
+## java -Dfile.encoding="UTF-8" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -Xms1g -Xmx4g -jar spigot-1.8.8.jar nogui --log-strip-color
+## pause
+##
+## 3. When viewing the logs/latest.log files you must use an editor such as NotePad instead of WordPad.
+##
+## 4. Unicode is properly displayed in game, in console, in the logs, and with paste.helpch.at when using
+## /prison support submit.
+##
+
+
+# NOTE: A messages__version is an arbitrary integer that will be manually incremented within Prison
+# when there are changes to these messages. This value represents when message content is
+# changed, fixed, or added to. This value may not be increased if the change is very small and
+# insignificant, such as a space or a couple of letters.
+#
+# messages__auto_refresh=true indicates that this file will automatically be replaced if
+# Prison detects a messages__version difference. The old file will be deleted (renamed) and
+# a new copy will be placed in the directory to be used. If this value is set to false, then
+# Prison will not refresh this file and there could be issues with the display of other messages.
+# If auto refresh is set to false, we are not held responsible for possible issues that can
+# arise from inaccurate messages. If set to false, then you are responsible for maintaining
+# the messages on your own.
+#
+# If you make changes to this file, and you have messages__auto_refresh=false, then those
+# changes will be replaced when this file is updated. Since the old file is renamed, and
+# not deleted, you can manually merge your changes back in to the new update. The old
+# renamed files will never be deleted by prison; you can remove them when you feel like it
+# is safe to do so.
+#
+# Please consider helping Prison, and everyone else who may use Prison, by contributing all
+# translations to other languages. They should be faithful translations, and not something
+# for the sake of humor or changes just for cosmetic styling. If you have something you would
+# like to share, please contact a staff member on our Discord server.
+#Thanks for your contributions!
+#
+messages__version=9
+messages__auto_refresh=true
+
+
+core_output__prefix_template=| %1 | &7
+core_output__prefix_template_prison=Prison
+core_output__prefix_template_info=Info
+core_output__prefix_template_warning=Varoitus
+core_output__prefix_template_error=Error
+core_output__prefix_template_debug=Debug
+
+core_output__color_code_info=&3
+core_output__color_code_warning=&c
+core_output__color_code_error=&c
+core_output__color_code_debug=&9
+
+core_output__error_startup_failure=Prison: (Sending to System.err due to Output.log Logger failure):
+core_output__error_incorrect_number_of_parameters=Log Failure (%1): Incorrect number of parameters: [%2] Original raw message: [%3] Arguments: %4
+
+
+core_text__prefix=&3
+core_text__just_now=nytten
+core_text__ago=sitten
+core_text__from_now=tästä lähtien
+core_text__and=ja
+core_text__time_units_prefix_spacer=
+core_text__time_units_singular=vuosi,kuukausi,viikko,päivä,tunti,minuutti,sekuntti
+core_text__time_units_plural=vuodet,kuukaudet,viikot,päivät,tunnit,minuutit,sekuntit
+core_text__time_units_short=y,m,w,d,h,m,s
+
+
+core_tokens__name_required=Prison Tokens=A player's name is required when used from console.
+core_tokens__cannot_view_others_balances=Prison Tokens: You do not have permission to view other player's balances.
+core_tokens__view_balance=&3%1 has %2 tokens.
+core_tokens__add_invalid_amount=Prison Tokens: Määrää ei tunnistettu: '%1'. Pitää olla ylempi kuin nolla.
+core_tokens__added_amount=&3%1 on &7%2 &3tokeneita lisättyä &7%3&3.
+core_tokens__removed_amount=&3%1 nyt on &7%2 &3tokeneita poistettua &7%3&3.
+core_tokens__set_amount=&3%1 on nyt &7%2 &3tokenia.
+
+
+core_runCmd__name_required=pelaajan nimi vaaditaan.
+core_runCmd__command_required=komento vaaditaan.
+
+
+core_prison_utf8_test=test
+
+
+# The following are the original messages and they will eventually be replaced.
+
+includeError=[%1] has an invalid value.
+excludeError=[%1] has an invalid value.
+cantAsConsole=You can't do this as console.
+missingArgument=The argument [%1] is not defined (it has no default value).
+missingFlagArgument=The flag -%1 does not have the required parameters.
+undefinedFlagArgument=The argument [%1] to the flag -%2 is not defined.
+internalErrorOccurred=An internal error occurred while attempting to perform this command.
+noPermission=You lack the necessary permissions to perform this command.
+blockParseError=The parameter [%1] is not a valid block.
+numberParseError=The parameter [%1] is not a number.
+numberTooLow=The parameter [%1] must be equal or greater than %2.
+numberTooHigh=The parameter [%1] must be equal or less than %2.
+numberRangeError=The parameter [%1] must be equal or greater than %2 and less than or equal to %3.
+tooFewCharacters=The parameter [%1] must be equal or greater than %2 characters.
+tooManyCharacters=The parameter [%1] must be equal or less than %2 characters.
+playerNotOnline=The player %1 is not online.
+worldNotFound=The world %1 was not found.
+
+
+
+
+
+core_gui__click_to_decrease=&3Click to decrease.
+core_gui__click_to_increase=&3Click to increase.
+
+
+core_gui__click_to_cancel=&3Click to cancel.
+core_gui__click_to_close=&3Click to close.
+core_gui__click_to_confirm=&3Click to confirm.
+core_gui__click_to_delete=&3Click to delete.
+core_gui__click_to_disable=&3Click to disable.
+core_gui__click_to_edit=&3Click to edit.
+core_gui__click_to_enable=&3Click to enable.
+core_gui__click_to_open=&3Click to open.
+
+
+core_gui__left_click_to_confirm=&3Left-Click to confirm.
+core_gui__left_click_to_reset=&3Left-Click to reset.
+core_gui__left_click_to_open=&3Left-Click to open.
+core_gui__left_click_to_edit=&3Left-Click to edit.
+
+
+core_gui__right_click_to_cancel=&3Right-Click to cancel.
+core_gui__right_click_to_delete=&3Right-Click to delete.
+core_gui__right_click_to_disable=&3Right-Click to disable.
+core_gui__right_click_to_enable=&3Right-Click to enable.
+core_gui__right_click_to_toggle=&3Right-Click to toggle.
+
+
+core_gui__right_click_and_shift_to_delete=&3Right-Click and shift to delete.
+core_gui__right_click_and_shift_to_disable=&3Right-Click and shift to disable.
+core_gui__right_click_and_shift_to_toggle=&3Right-Click and shift to toggle.
+
+
+core_gui__page_next=&3Next page.
+core_gui__page_prior=&3Prior page.
+
+
+core_gui__money_earned=&3You earned &a$%1
+core_gui__price=&3Price: %1
+core_gui__confirm=&3Confirm: %1 %2
+core_gui__delay=&3Delay: %1 secs
+core_gui__multiplier=&3Multiplier: x %1
+core_gui__value=&3Value: %1
+core_gui__permission=&3Permission: &7%1
+core_gui__prestige_name=&3Prestige name: %1
+
diff --git a/prison-core/src/main/resources/lang/mines/fi_FI.properties b/prison-core/src/main/resources/lang/mines/fi_FI.properties
new file mode 100644
index 000000000..4c3af869f
--- /dev/null
+++ b/prison-core/src/main/resources/lang/mines/fi_FI.properties
@@ -0,0 +1,99 @@
+# NOTE: A messages__version is an arbitrary integer that will be manually incremented within Prison
+# when there are changes to these messages. This value represents when message content is
+# changed, fixed, or added to. This value may not be increased if the change is very small and
+# insignificant, such as a space or a couple of letters.
+#
+# messages__auto_refresh=true indicates that this file will automatically be replaced if
+# Prison detects a messages__version difference. The old file will be deleted (renamed) and
+# a new copy will be placed in the directory to be used. If this value is set to false, then
+# Prison will not refresh this file and there could be issues with the display of other messages.
+# If auto refresh is set to false, we are not held responsible for possible issues that can
+# arise from inaccurate messages. If set to false, then you are responsible for maintaining
+# the messages on your own.
+#
+# If you make changes to this file, and you have messages__auto_refresh=false, then those
+# changes will be replaced when this file is updated. Since the old file is renamed, and
+# not deleted, you can manually merge your changes back in to the new update. The old
+# renamed files will never be deleted by prison; you can remove them when you feel like it
+# is safe to do so.
+#
+# Please consider helping Prison, and everyone else who may use Prison, by contributing all
+# translations to other languages. They should be faithful translations, and not something
+# for the sake of humor or changes just for cosmetic styling. If you have something you would
+# like to share, please contact a staff member on our Discord server.
+#Thanks for your contributions!
+#
+
+##
+## Prison Supports Unicode (UTF-8) encoding in these properties files. BUt you must
+## follow these instructions to ensure everything works properly.
+##
+## 1. You should only edit these files using a UTF-8 editor. On windows use NotePad, not WordPad.
+## WordPad will save as plain text. To confirm the save was successful: save, close the editor,
+## then reopen to confirm the encoding was preserved.
+##
+## 2. When running on Windows, you must enable utf-8 encoding in minecraft's console. Windows
+## defaults to a characterpage 1252. To enable window's use of utf-8, you need to change the
+## encoding prior to launching spigot/paper:
+## chcp 65001
+##
+## Full example of a windows script, which hooks for java debugging:
+## rem Note: chcp 65001 enables utf-8 in windows, when normally windows uses characterpage 1252
+## chcp 65001
+## java -Dfile.encoding="UTF-8" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -Xms1g -Xmx4g -jar spigot-1.8.8.jar nogui --log-strip-color
+## pause
+##
+## 3. When viewing the logs/latest.log files you must use an editor such as NotePad instead of WordPad.
+##
+## 4. Unicode is properly displayed in game, in console, in the logs, and with paste.helpch.at when using
+## /prison support submit.
+##
+
+
+
+messages__version=3
+messages__auto_refresh=true
+
+
+
+# The following are the original messages and they will eventually be replaced.
+
+reset_warning=&7Mine %1 resettaa &3%2&7.
+reset_message=&7mine %1 on resetattu.
+not_allowed=&7Et voi mainata täällä.
+autosmelt_enable=&bAutosmelt &7on &akäytössä&7.
+autosmelt_disable=&bAutosmelt &7on &cdisabloitu&7.
+autoblock_enable=&bAutoblock &7on &aenabloitu&7.
+autoblock_disable=&bAutoblock &7on &cdisabloitu&7.
+autopickup_enable=&bAutopickup &7on &aenabloitu&7.
+autopickup_disable=&bAutopickup &7on &cdisabloitu&7.
+teleported=&7Teleporttaa minelle &3%1&7.
+mine_reset=&7mine &3%1&7 on resetattu.
+mine_reset_fail=&7Ei pystytty resetoimaan mainia &3%1&7. &8Katso consolesta lisätietoa.
+mine_created=&7Onnistuneesti luotu maini!.
+mine_deleted=&7Onnistuneesti poistettu maini!.
+select_bounds=&7Sinun pitää valita mainin alue ekana. &8Tee /mines wand jotta voit tehdä niin.
+world_diff=&7Et voi tehdä maineja kahden mailman väliin..
+mine_exists=&7Maini sillä nimellä on jo olemassa.
+mine_does_not_exist=&7Maini sillä nimellä ei löydy.
+spawn_set=&7Mainin spawni on asetettu.
+spawn_removed=&7Mainin spawni on onnistuneesti poistettu.
+spawnpoint_same_world=&cspawnpoint &7pitää olla samassa mailmassa kuin maini.
+not_a_block=&c%1 &7ei ole blockki.
+block_already_added=&7Tämä blockki on jo lisätty mainiin..
+mine_full=&cMaini on jo täynnä.
+block_added=&7Lisätty &3%1 &7mainiin &3%2&7.
+block_set=&7Vaihdettu blocki &3%1 &7mainissa &3%2&7.
+block_not_removed=&7Tämä blocki ei ole minessa.
+block_deleted=&7Blocki &3%1 &7on poistettu mainista &3%2&7.
+mine_redefined=&7onnistuneesti &3redefined &7maini.
+missing_world=&7Mailma jossa mainit luotiin ei löydy..
+block_search_blank=&7Kirjoita arvo etsiessäsi blockia&7.
+
+mines_mtp__unable_to_teleport=Et voi teleporttaa siihen.
+mines_mtp__unable_to_teleport_others=&3Et voi teleporata toisen pelaajan mainiin.
+mines_mtp__no_target_mine_found=Mainia ei löytynyt. &3Yritä uudestaan eri nimellä.
+mines_mtp__player_must_be_in_game=mines_mtp__player_must_be_in_game
+mines_mtp__player_must_be_in_game=&3Pelaaja ei ole pelissä.
+mines_mtp__cannot_use_virtual_mines=&cInvalid option. This mine is a virtual mine&7. Use &a/mines set area &7to enable the mine.
+mines_mtp__teleport_failed=&3Teleporttaus epäonnistui, oletko pelaaja?
diff --git a/prison-core/src/main/resources/lang/sellall/fi_FI.properties b/prison-core/src/main/resources/lang/sellall/fi_FI.properties
new file mode 100644
index 000000000..059de9f6b
--- /dev/null
+++ b/prison-core/src/main/resources/lang/sellall/fi_FI.properties
@@ -0,0 +1,67 @@
+# NOTE: A messages__version is an arbitrary integer that will be manually incremented within Prison
+# when there are changes to these messages. This value represents when message content is
+# changed, fixed, or added to. This value may not be increased if the change is very small and
+# insignificant, such as a space or a couple of letters.
+#
+# messages__auto_refresh=true indicates that this file will automatically be replaced if
+# Prison detects a messages__version difference. The old file will be deleted (renamed) and
+# a new copy will be placed in the directory to be used. If this value is set to false, then
+# Prison will not refresh this file and there could be issues with the display of other messages.
+# If auto refresh is set to false, we are not held responsible for possible issues that can
+# arise from inaccurate messages. If set to false, then you are responsible for maintaining
+# the messages on your own.
+#
+# If you make changes to this file, and you have messages__auto_refresh=false, then those
+# changes will be replaced when this file is updated. Since the old file is renamed, and
+# not deleted, you can manually merge your changes back in to the new update. The old
+# renamed files will never be deleted by prison; you can remove them when you feel like it
+# is safe to do so.
+#
+# Please consider helping Prison, and everyone else who may use Prison, by contributing all
+# translations to other languages. They should be faithful translations, and not something
+# for the sake of humor or changes just for cosmetic styling. If you have something you would
+# like to share, please contact a staff member on our Discord server.
+#Thanks for your contributions!
+#
+
+##
+## Prison Supports Unicode (UTF-8) encoding in these properties files. BUt you must
+## follow these instructions to ensure everything works properly.
+##
+## 1. You should only edit these files using a UTF-8 editor. On windows use NotePad, not WordPad.
+## WordPad will save as plain text. To confirm the save was successful: save, close the editor,
+## then reopen to confirm the encoding was preserved.
+##
+## 2. When running on Windows, you must enable utf-8 encoding in minecraft's console. Windows
+## defaults to a characterpage 1252. To enable window's use of utf-8, you need to change the
+## encoding prior to launching spigot/paper:
+## chcp 65001
+##
+## Full example of a windows script, which hooks for java debugging:
+## rem Note: chcp 65001 enables utf-8 in windows, when normally windows uses characterpage 1252
+## chcp 65001
+## java -Dfile.encoding="UTF-8" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -Xms1g -Xmx4g -jar spigot-1.8.8.jar nogui --log-strip-color
+## pause
+##
+## 3. When viewing the logs/latest.log files you must use an editor such as NotePad instead of WordPad.
+##
+## 4. Unicode is properly displayed in game, in console, in the logs, and with paste.helpch.at when using
+## /prison support submit.
+##
+
+messages__version=1
+messages__auto_refresh=true
+
+
+sellall_function__message=&dNormaali viesti
+
+
+
+sellall_spigot_utils__money_earned=&3Tienasit &a$%1
+sellall_spigot_utils__only_sellall_signs_are_enabled=&3Voit vain myydä kylteillä, komento disabloitu.
+sellall_spigot_utils__rate_limit_exceeded=&3Hidasta..
+sellall_spigot_utils__shop_is_empty=&3Anteeksi, tämä myynti kauppa on tyhjä..
+sellall_spigot_utils__you_have_nothing_to_sell=&3Anteeksi, sinulla ei ole myytävää.
+
+sellall_spigot_utils__sellall_is_disabled=&3Anteeksi, sellall on disabloitu
+
From 44badd007b3969b43ea3899cdbf112483af268f6 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Wed, 28 Dec 2022 22:44:31 -0500
Subject: [PATCH 066/129] v3.3.0-alpha.13g 2022-12-28
---
docs/changelog_v3.3.x.md | 6 +++++-
gradle.properties | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index f87c6b93b..4cebab22d 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,11 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13f 2022-12-28
+# 3.3.0-alpha.13g 2022-12-28
+
+
+* **v3.3.0-alpha.13g 2022-12-28**
+
* **Added Finnish translations to prison!**
Thearex12 contributed a number of Finnish translations for prison in the following
diff --git a/gradle.properties b/gradle.properties
index 5d0883708..b28329be9 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,7 +3,7 @@
## # This is actually the "correct" place to define the version for the project.
## # Used within build.gradle with ${project.version}.
## # Can be overridden on the command line: gradle -Pversion=3.2.1-alpha.3
-version=3.3.0-alpha.13f
+version=3.3.0-alpha.13g
From 8a15ffb9ef700be766ef4b380d725aea5ae6a01f Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 01:22:36 -0500
Subject: [PATCH 067/129] Added a new command `/prison support cmdStats` which
shows some basic stats on command usage.
---
docs/changelog_v3.3.x.md | 5 ++-
.../tech/mcprison/prison/PrisonCommand.java | 42 +++++++++++++++++++
.../prison/commands/CommandHandler.java | 36 ++++++++--------
.../prison/commands/RegisteredCommand.java | 38 ++++++++++++++---
.../mcprison/prison/commands/RootCommand.java | 7 ++--
5 files changed, 100 insertions(+), 28 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 4cebab22d..7dc2cde29 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -10,7 +10,10 @@
These build logs represent the work that has been going on within prison.
-# 3.3.0-alpha.13g 2022-12-28
+# 3.3.0-alpha.13g 2022-12-29
+
+
+* **Added a new command `/prison support cmdStats` which shows some basic stats on command usage.**8
* **v3.3.0-alpha.13g 2022-12-28**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 27f17d1db..504f09d54 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -28,6 +28,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.UUID;
import tech.mcprison.prison.autofeatures.AutoFeaturesFileConfig.AutoFeatures;
@@ -39,6 +40,7 @@
import tech.mcprison.prison.commands.Arg;
import tech.mcprison.prison.commands.Command;
import tech.mcprison.prison.commands.CommandPagedData;
+import tech.mcprison.prison.commands.RegisteredCommand;
import tech.mcprison.prison.commands.Wildcard;
import tech.mcprison.prison.discord.PrisonPasteChat;
import tech.mcprison.prison.internal.CommandSender;
@@ -1155,6 +1157,46 @@ public void findCommand(CommandSender sender,
command, registered );
}
+
+
+ @Command(identifier = "prison support cmdStats",
+ description = "Stats on Prison command stats. Only shows actual commands that are used.",
+ onlyPlayers = false, permissions = "prison.debug" )
+ public void statsCommand(CommandSender sender ) {
+
+ List cmds = getCommandStats();
+ for (String cmd : cmds) {
+
+ Output.get().logInfo( cmd );
+ }
+ }
+
+ private List getCommandStats() {
+ List results = new ArrayList<>();
+
+ DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+
+ TreeSet allCmds = Prison.get().getCommandHandler().getAllRegisteredCommands();
+
+ results.add( "Prison Command Statss:" );
+
+ int totals = 0;
+ for (RegisteredCommand cmd : allCmds) {
+
+ if ( cmd.getUsageCount() > 0 ) {
+ results.add( Output.stringFormat( " &3/%-40s &7%7s",
+ cmd.getCompleteLabel(),
+ dFmt.format( cmd.getUsageCount() )) );
+ totals += cmd.getUsageCount();
+ }
+ }
+
+ results.add( Output.stringFormat(" &3Total Registered Prison Commands: &7%9s", dFmt.format( allCmds.size() )) );
+ results.add( Output.stringFormat(" &3Total Prison Commands Listed: &7%9s", dFmt.format( allCmds.size() )) );
+ results.add( Output.stringFormat(" &3Total Prison Command Usage: &7%9s", dFmt.format( totals )) );
+
+ return results;
+ }
@Command(identifier = "prison support runCmd",
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
index 6e0952ef9..c4e6759b8 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/CommandHandler.java
@@ -687,25 +687,25 @@ private RegisteredCommand commandRegisterConfig( Method method, Command commandA
RegisteredCommand mainCommand = getRootCommands().get( rootPluginCommand );
- for (int i = 1; i < identifiers.length; i++) {
-
- String suffix = identifiers[i];
- if ( mainCommand.doesSuffixCommandExist(suffix) ) {
- mainCommand = mainCommand.getSuffixCommand(suffix);
- }
- else {
- RegisteredCommand newCommand = new RegisteredCommand(suffix, this, mainCommand);
- newCommand.setAlias( alias != null );
- mainCommand.addSuffixCommand(suffix, newCommand);
-
- // Must add all new RegisteredCommand objects to both getAllRegisteredCommands() and
- // getTabCompleterData().
- getAllRegisteredCommands().add( newCommand );
- getTabCompleaterData().add( newCommand );
-
- mainCommand = newCommand;
- }
+ for (int i = 1; i < identifiers.length; i++) {
+
+ String suffix = identifiers[i];
+ if ( mainCommand.doesSuffixCommandExist(suffix) ) {
+ mainCommand = mainCommand.getSuffixCommand(suffix);
+ }
+ else {
+ RegisteredCommand newCommand = new RegisteredCommand(suffix, this, mainCommand );
+ newCommand.setAlias( alias != null );
+ mainCommand.addSuffixCommand(suffix, newCommand);
+
+ // Must add all new RegisteredCommand objects to both getAllRegisteredCommands() and
+ // getTabCompleterData().
+ getAllRegisteredCommands().add( newCommand );
+ getTabCompleaterData().add( newCommand );
+
+ mainCommand = newCommand;
}
+ }
// Associate the last RegisteredCommand (mainCommand) with the rootPCommand since that is
// the leaf-node that will be tied to the registered command, especially with aliases:
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
index fcd3fb65b..17265b686 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
@@ -42,6 +42,8 @@ public class RegisteredCommand
private RegisteredCommand parent;
private boolean alias = false;
+ private int usageCount;
+
private String junitTest = null;
private String description;
@@ -78,6 +80,8 @@ public RegisteredCommand(String label, CommandHandler handler, RegisteredCommand
this.parent = parent;
this.registeredAliases = new ArrayList<>();
+
+ this.usageCount = 0;
}
/**
@@ -153,7 +157,7 @@ public String getCompleteLabel() {
* @param sender
* @param args
*/
- void execute(CommandSender sender, String[] args) {
+ protected void execute(CommandSender sender, String[] args) {
// First ensure the player is not locked out of this command:
if ( !handler.hasCommandAccess(sender, this, getLabel(), args) ) {
@@ -188,21 +192,26 @@ void execute(CommandSender sender, String[] args) {
// (args == null ? "null" : args.length) +
// " args[0] == " + args[0]);
- executeMethod(sender, args);
+ // all checks were passed, and this is where the
+ // command is executed...
+ executeMethod( sender, args );
}
else {
// Strip first arg, then recursively try again
String[] nargs = new String[args.length - 1];
System.arraycopy(args, 1, nargs, 0, args.length - 1);
- command.execute(sender, nargs);
+ command.execute( sender, nargs );
}
- } else {
- executeMethod(sender, args);
+ }
+ else {
+ // all checks were passed, and this is where the
+ // command is executed...
+ executeMethod( sender, args );
}
}
- private void executeMethod(CommandSender sender, String[] args) {
+ private void executeMethod(CommandSender sender, String[] args ) {
if (!set) {
sendHelpMessage(sender);
return;
@@ -233,6 +242,12 @@ private void executeMethod(CommandSender sender, String[] args) {
try {
try {
+ // The command is ran here with the invoke...
+
+ // Record that the command has been "ran", which does not mean it was successful:
+ incrementUsageCount();
+
+
method.invoke(getMethodInstance(), resultArgs.toArray());
}
catch ( IllegalArgumentException | InvocationTargetException e) {
@@ -578,4 +593,15 @@ public int compareTo( RegisteredCommand arg0 )
return getUsage().compareTo( arg0.getUsage() );
}
+
+ public void incrementUsageCount() {
+ usageCount++;
+ }
+ public int getUsageCount() {
+ return usageCount;
+ }
+ public void setUsageCount(int usageCount) {
+ this.usageCount = usageCount;
+ }
+
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/RootCommand.java b/prison-core/src/main/java/tech/mcprison/prison/commands/RootCommand.java
index c6aedbb3e..05992fc6c 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/RootCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/RootCommand.java
@@ -24,8 +24,8 @@ public class RootCommand extends RegisteredCommand {
private PluginCommand root;
- RootCommand(PluginCommand root, CommandHandler handler) {
- super(root.getLabel(), handler, null);
+ RootCommand(PluginCommand root, CommandHandler handler ) {
+ super(root.getLabel(), handler, null );
this.root = root;
}
@@ -33,7 +33,8 @@ public PluginCommand getBukkitCommand() {
return root;
}
- @Override void set(Object methodInstance, Method method) {
+ @Override
+ protected void set(Object methodInstance, Method method) {
super.set(methodInstance, method);
root.setDescription(getDescription());
root.setUsage(getUsage());
From a0c6ff7e6a4175f0caa8db33fcb292a133d9cde1 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 02:58:08 -0500
Subject: [PATCH 068/129] Fix the use of `{br}` when using `/prison support
submit version` so that it is now treated as `\n`. Added to the `/prison
support submit version` all listeners and the command stats too.
---
.../tech/mcprison/prison/PrisonCommand.java | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 504f09d54..15be1250f 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -1277,7 +1277,30 @@ public void supportSubmitVersion(CommandSender sender
StringBuilder text = Prison.get().getPrisonStatsUtil().getSupportSubmitVersionData();
+
+ int idx = text.indexOf("{br}");
+ while ( idx != -1 ) {
+ // Convert `{br}` to `\n`:
+ text.replace(idx, idx+4, "\n");
+
+ idx = text.indexOf("{br}");
+ }
+
+ // Add all of the listeners details:
+ text.append( "\n\n" );
+ text.append(
+ Prison.get().getPrisonStatsUtil().getSupportSubmitListenersData( "all" )
+ );
+
+ // Include the command stats:
+ text.append( "\n\n" );
+ List cmdStats = getCommandStats();
+ for (String cmd : cmdStats) {
+ text.append( cmd ).append( "\n" );
+ }
+
+
PrisonPasteChat pasteChat = new PrisonPasteChat( getSupportName(), getSupportURLs() );
String helpURL = pasteChat.post( text.toString() );
From 8d314dcc727f17d653d71ab4210c18dc0990ec22 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 02:59:21 -0500
Subject: [PATCH 069/129] Fixed the prison command stats to show the correct
number of commands listed.
---
docs/changelog_v3.3.x.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 7dc2cde29..809a2738a 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,13 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13g 2022-12-29
+* **Fixed the prison command stats to show the correct number of commands listed.**
+
+
+* **Fix the use of `{br}` when using `/prison support submit version` so that it is now treated as `\n`.
+Added to the `/prison support submit version` all listeners and the command stats too.**
+
+
* **Added a new command `/prison support cmdStats` which shows some basic stats on command usage.**8
From da4d37e5c38e5596a84f6169104a7f7e5a8a6cc4 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 02:59:52 -0500
Subject: [PATCH 070/129] Fixed the prison command stats to show the correct
number of commands listed.
---
.../src/main/java/tech/mcprison/prison/PrisonCommand.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 15be1250f..3b1844545 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -1180,6 +1180,7 @@ private List getCommandStats() {
results.add( "Prison Command Statss:" );
+ int count = 0;
int totals = 0;
for (RegisteredCommand cmd : allCmds) {
@@ -1187,12 +1188,13 @@ private List getCommandStats() {
results.add( Output.stringFormat( " &3/%-40s &7%7s",
cmd.getCompleteLabel(),
dFmt.format( cmd.getUsageCount() )) );
+ count++;
totals += cmd.getUsageCount();
}
}
results.add( Output.stringFormat(" &3Total Registered Prison Commands: &7%9s", dFmt.format( allCmds.size() )) );
- results.add( Output.stringFormat(" &3Total Prison Commands Listed: &7%9s", dFmt.format( allCmds.size() )) );
+ results.add( Output.stringFormat(" &3Total Prison Commands Listed: &7%9s", dFmt.format( count )) );
results.add( Output.stringFormat(" &3Total Prison Command Usage: &7%9s", dFmt.format( totals )) );
return results;
From f715200007fb7c6d291c5daa4a8cc9fb7867806c Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 03:02:51 -0500
Subject: [PATCH 071/129] Added a prison backup save command (renamed the
original prison backup) and added a prison backup logs command that shows all
entries in the backup log file. The contents of the backup log file has been
added to the /prison support submit version command too.
---
docs/changelog_v3.3.x.md | 4 ++
.../tech/mcprison/prison/PrisonCommand.java | 38 ++++++++++++++++++-
.../prison/backups/PrisonBackups.java | 24 +++++++++++-
.../mcprison/prison/chat/FancyMessage.java | 3 ++
.../tech/mcprison/prison/output/Output.java | 14 +++++--
.../mcprison/prison/output/TextComponent.java | 2 +-
6 files changed, 79 insertions(+), 6 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 809a2738a..8d99adc89 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -13,6 +13,10 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13g 2022-12-29
+* **Added a prison backup save command (renamed the original prison backup) and added a prison backup logs command that shows all entries in the backup log file.**
+The contents of the backup log file has been added to the /prison support submit version command too.
+
+
* **Fixed the prison command stats to show the correct number of commands listed.**
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 3b1844545..398366e63 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -1303,6 +1303,17 @@ public void supportSubmitVersion(CommandSender sender
}
+
+ // Include Prison backup logs:
+ text.append( "\n\n" );
+ text.append( "Prison Backup Logs:" ).append( "\n" );
+ List backupLogs = getPrisonBackupLogs();
+
+ for (String log : backupLogs) {
+ text.append( Output.decodePercentEncoding(log) ).append( "\n" );
+ }
+
+
PrisonPasteChat pasteChat = new PrisonPasteChat( getSupportName(), getSupportURLs() );
String helpURL = pasteChat.post( text.toString() );
@@ -1802,7 +1813,7 @@ public void supportListenersDump(CommandSender sender,
}
- @Command(identifier = "prison support backup",
+ @Command(identifier = "prison support backup save",
description = "This will make a backup of all Prison settings by creating a new " +
"zip file which will be stored in the directory plugins/Prison/backups. " +
"After creating the backup, this will delete all temp files, backup files, etc.. " +
@@ -1823,7 +1834,32 @@ public void supportBackupPrison( CommandSender sender,
sender.sendMessage( "Backup finished." );
}
+
+ @Command(identifier = "prison support backup logs",
+ description = "This will list Prison backup logs that are in the file "
+ + "`plugins/Prison/backup/versions.log`",
+ onlyPlayers = false, permissions = "prison.debug" )
+ public void supportBackupList( CommandSender sender ) {
+
+ ChatDisplay display = new ChatDisplay("Prison Backup Logs:");
+
+ List backupLogs = getPrisonBackupLogs();
+
+ for (String log : backupLogs) {
+ display.addText(log);
+ }
+
+ display.send(sender);
+
+ }
+
+ private List getPrisonBackupLogs() {
+ PrisonBackups prisonBackup = new PrisonBackups();
+ List backupLogs = prisonBackup.backupReport02BackupLog();
+ return backupLogs;
+ }
+
@Command(identifier = "prison tokens balance",
description = "Prison tokens: a player's current balance.",
// aliases = "tokens bal",
diff --git a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
index 04f17bbf4..45678bd39 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/backups/PrisonBackups.java
@@ -20,7 +20,8 @@
public class PrisonBackups {
public static final String FILE_BACKUP_DIRECTORY_PATH = "backups";
- public static final String FILE_BACKUP_VERSIONS_FILE = FILE_BACKUP_DIRECTORY_PATH + "/versions.log";
+ public static final String FILEBACKUP_VERSIONS_FILE_NAME = "/versions.log";
+ public static final String FILE_BACKUP_VERSIONS_FILE = FILE_BACKUP_DIRECTORY_PATH + FILEBACKUP_VERSIONS_FILE_NAME;
public static final String VERSIONS_FILE_VERSION_PREFIX = "New_Prison_Version:";
public static final String VERSIONS_FILE_BACKUP_MADE_PREFIX = "Backup:";
@@ -293,6 +294,27 @@ public String backupReport01() {
return msg1;
}
+
+ public List backupReport02BackupLog() {
+ List results = new ArrayList<>();
+
+ File backupDir = getBackupDirectoryFile();
+
+ File backupLogFile = new File( backupDir, FILEBACKUP_VERSIONS_FILE_NAME );
+
+ try {
+ results = Files.readAllLines( backupLogFile.toPath() );
+ }
+ catch (IOException e) {
+ results.add(
+ Output.stringFormat( "\n\nError reading %s. [%s]",
+ backupLogFile.toString(), e.getMessage() ) );
+ }
+
+ return results;
+ }
+
+
public StringBuilder backupReportVersionData() {
return Prison.get().getPrisonStatsUtil().getSupportSubmitVersionData();
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/chat/FancyMessage.java b/prison-core/src/main/java/tech/mcprison/prison/chat/FancyMessage.java
index c469709b0..9003b9c00 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/chat/FancyMessage.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/chat/FancyMessage.java
@@ -612,6 +612,9 @@ public String toJSONString() {
}
jsonString = string.toString();
dirty = false;
+
+ jsonString = Output.decodePercentEncoding(jsonString);
+
return jsonString;
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/output/Output.java b/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
index 0dd5171d4..7b19517d0 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/output/Output.java
@@ -236,6 +236,13 @@ public static String stringFormat( String message, Object... args ) {
return msg;
}
+ public static String decodePercentEncoding( String message ) {
+ if ( message.contains( PERCENT_ENCODING ) ) {
+ message = message.replace( PERCENT_ENCODING, PERCENT_DECODING );
+ }
+ return message;
+ }
+
/**
* Log a message with a specified {@link LogLevel}
*/
@@ -267,9 +274,10 @@ else if ( Prison.get() == null || Prison.get().getPlatform() == null ) {
message :
String.format(message, args);
- if ( msg.contains( PERCENT_ENCODING ) ) {
- msg = msg.replace( PERCENT_ENCODING, PERCENT_DECODING );
- }
+ msg = decodePercentEncoding( msg );
+// if ( msg.contains( PERCENT_ENCODING ) ) {
+// msg = msg.replace( PERCENT_ENCODING, PERCENT_DECODING );
+// }
Prison.get().getPlatform().log(
prefixTemplatePrison + " " +
diff --git a/prison-core/src/main/java/tech/mcprison/prison/output/TextComponent.java b/prison-core/src/main/java/tech/mcprison/prison/output/TextComponent.java
index 7336b483b..b92b7095d 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/output/TextComponent.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/output/TextComponent.java
@@ -31,7 +31,7 @@ public class TextComponent extends DisplayComponent {
protected String text;
public TextComponent(String text, Object... args) {
- this.text = String.format(text, args);
+ this.text = Output.stringFormat(text, args);
}
@Override public String text() {
From 1a9c8e6d7ad9b88f8008deb2c7ef9a98f67f89cb Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 05:05:31 -0500
Subject: [PATCH 072/129] Update various libraries used in the gradle build:
placeholderApi: v2.10.9 to v2.11.2 XSeries: v9.0.0 to v9.2.0 item-nbt-api:
v2.10.0 to v2.11.1 removal of mvdw from the gradle build since it was removed
from prison a few months ago
---
docs/changelog_v3.3.x.md | 6 ++++++
prison-spigot/build.gradle | 36 ++++++++++++++++++++++--------------
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index 8d99adc89..b6bc080d0 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,6 +12,12 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13g 2022-12-29
+* **Update various libraries used in the gradle build:**
+placeholderApi: v2.10.9 to v2.11.2
+XSeries: v9.0.0 to v9.2.0
+item-nbt-api: v2.10.0 to v2.11.1
+removal of mvdw from the gradle build since it was removed from prison a few months ago
+
* **Added a prison backup save command (renamed the original prison backup) and added a prison backup logs command that shows all entries in the backup log file.**
The contents of the backup log file has been added to the /prison support submit version command too.
diff --git a/prison-spigot/build.gradle b/prison-spigot/build.gradle
index b7349d3bb..bbce83f12 100644
--- a/prison-spigot/build.gradle
+++ b/prison-spigot/build.gradle
@@ -41,12 +41,14 @@ repositories {
maven { url = "https://repo.codemc.org/repository/maven-public/" }
//maven { url = "https://repo.inventivetalent.org/content/groups/public/" }
- maven {
- url = "https://repo.mvdw-software.be/content/groups/public/"
- content {
- includeGroup 'be.maximvdw'
- }
- }
+
+// NOTE: mvdw support has been removed from prison since PAPI works with it:
+// maven {
+// url = "https://repo.mvdw-software.be/content/groups/public/"
+// content {
+// includeGroup 'be.maximvdw'
+// }
+// }
maven {
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
content {
@@ -104,7 +106,8 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.12.0'
- compileOnly 'me.clip:placeholderapi:2.10.9'
+ compileOnly 'me.clip:placeholderapi:2.11.2'
+ //compileOnly 'me.clip:placeholderapi:2.10.9'
// Repo may be hosted: https://hub.spigotmc.org/nexus/content/groups/public/
// But do not see v5.0
@@ -116,7 +119,8 @@ dependencies {
// implementation 'com.github.cryptomorin:xseries:b95d195482'
// https://mvnrepository.com/artifact/com.github.cryptomorin/XSeries
- implementation 'com.github.cryptomorin:XSeries:9.0.0'
+ implementation 'com.github.cryptomorin:XSeries:9.2.0'
+ //implementation 'com.github.cryptomorin:XSeries:9.0.0'
//implementation 'com.github.cryptomorin:XSeries:8.8.0'
@@ -140,9 +144,9 @@ dependencies {
compileOnly 'net.milkbowl.vault:VaultAPI:1.7'
- compileOnly('be.maximvdw:MVdWPlaceholderAPI:2.5.2-SNAPSHOT'){
- exclude group: 'org.spigotmc'
- }
+// compileOnly('be.maximvdw:MVdWPlaceholderAPI:2.5.2-SNAPSHOT'){
+// exclude group: 'org.spigotmc'
+// }
// compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.1'
@@ -150,7 +154,8 @@ dependencies {
// NOTE: This maven repo was failing to be accessable during online builds. So added to the /lib.
// https://www.spigotmc.org/resources/nbt-api.7939/
// https://mvnrepository.com/artifact/de.tr7zw/item-nbt-api-plugin
- implementation 'de.tr7zw:item-nbt-api-plugin:2.10.0'
+ implementation 'de.tr7zw:item-nbt-api-plugin:2.11.1'
+// implementation 'de.tr7zw:item-nbt-api-plugin:2.10.0'
// implementation 'de.tr7zw:item-nbt-api-plugin:2.9.2'
@@ -207,12 +212,15 @@ shadowJar {
// include(dependency('org.bstats:bstats-base:2.2.1'))
// include(dependency('org.bstats:bstats-bukkit:2.2.1'))
- include(dependency('me.clip:placeholderapi:2.10.9'))
+ include(dependency('me.clip:placeholderapi:2.11.2'))
+ //include(dependency('me.clip:placeholderapi:2.10.9'))
+ //include(dependency('com.github.cryptomorin:XSeries:9.2.0'))
include(dependency('com.github.cryptomorin:XSeries:9.0.0'))
//include(dependency('com.github.cryptomorin:XSeries:8.8.0'))
- include(dependency('de.tr7zw:item-nbt-api-plugin:2.10.0'))
+ include(dependency('de.tr7zw:item-nbt-api-plugin:2.11.1'))
+ //include(dependency('de.tr7zw:item-nbt-api-plugin:2.10.0'))
//include(dependency('org.inventivetalent.spiget-update:bukkit:1.4.2-SNAPSHOT'))
//include(dependency('me.badbones69:crazyenchantments-plugin:1.8-Dev-Build-v8'))
From 5fde6cd7295ced654f8d0c3b0d22e758c2a4e3ea Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 12:39:40 -0500
Subject: [PATCH 073/129] Update docs
---
docs/knownissues_v3.3.x.md | 9 ++++++
...prison_docs_030_LuckPerms_Groups_Tracks.md | 30 +++++++++++++++++--
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/docs/knownissues_v3.3.x.md b/docs/knownissues_v3.3.x.md
index 8f43d3077..e52ca610f 100644
--- a/docs/knownissues_v3.3.x.md
+++ b/docs/knownissues_v3.3.x.md
@@ -8,6 +8,15 @@
# TODO Items for v3.3.0-alpha.13
+- On the new cmdStats details, add nano run times for commands so we can include avg run times.
+
+
+- Add a command usage count to commands. Then a simple report to list what commands were used, along with total command count of active commands.
+
+
+- Expand upon the config.yml command lockout so that if the player does not have access to a command, then suppress that command from all players, including command listings. Not all commands will be able to reject access due to the nature of the commands (all access to everyone) and/or the use of alt-perms (programmatic evaluation to the commands). - Josh-65
+
+
- File save to new format - OmarG
- pre-req for turning off TP
- pre-req for custom mine shapes
diff --git a/docs/prison_docs_030_LuckPerms_Groups_Tracks.md b/docs/prison_docs_030_LuckPerms_Groups_Tracks.md
index 2e8448b25..5feade8fe 100644
--- a/docs/prison_docs_030_LuckPerms_Groups_Tracks.md
+++ b/docs/prison_docs_030_LuckPerms_Groups_Tracks.md
@@ -383,22 +383,48 @@ There should be no configuration changes needed for the plugin, and it should ju
+
+
+
+# Special Variation: Accessing Only One Mine at a Time by using MineAccessByRank
+
+_Warning: This is a non-standard way of configuring access to your mines. These settings will only allow a player to access only the current mine and will exclude them from accessing prior mines._
+
+This setting will only allow players to access mines that are linked to their current rank. For example, if a player is at Rank C, then they cannot access the prior mines A nor B. This is a very restrictive configuration and is not generally typical of a prison server.
+
+
+Enable MineAccesByRank on all mines:
+
+`/mines set mineAccessByRank *all* enable`
+
+Then in the Prison `config.yml` file, enable this setting, using a value of *false*:
+
+```yaml
+prison-mines:
+ access-to-prior-mines: false
+```
+
+
# Special Variation: Accessing Only One Mine at a Time by using Permissions
+_Warning: This is a non-standard way of configuring access to your mines. These settings will only allow a player to access only the current mine and will exclude them from accessing prior mines._
+
+_Warning: It is not recommended to use Mine Access by Permissions; instead use MineAccessByRank._
+
One special variation in configuring your server, would be if players can "only" access mines that are tied to their current rank. For example, if a player is at Rank C, then they cannot access the prior mines A nor B. This is a very restrictive configuration, which requires managing the permissions.
-If you are using permissions for access, then the two you need to know about are: `mines.` and `mine..tp`. Such that mine A would require: `mines.a` and `mines.a.tp`.
+If you are using permissions for access, then the two you need to know about are: `mines.` and `mine.tp.`. Such that mine A would require: `mines.a` and `mines.tp.a`.
Add these two perms to all LuckPerm groups. You can use the LP editor, or manually with the following commands. Repeat for all groups.
```
/lp group a permission set mines.a true
-/lp group a permission set mines.a.tp true
+/lp group a permission set mines.tp.a true
```
From 05dfcbbb7804ea21e09c9f5ce3fc9519a3595e4a Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 12:40:25 -0500
Subject: [PATCH 074/129] Did not enable the correct version of XSeries.
---
prison-spigot/build.gradle | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/prison-spigot/build.gradle b/prison-spigot/build.gradle
index bbce83f12..b53d6fd6a 100644
--- a/prison-spigot/build.gradle
+++ b/prison-spigot/build.gradle
@@ -215,8 +215,8 @@ shadowJar {
include(dependency('me.clip:placeholderapi:2.11.2'))
//include(dependency('me.clip:placeholderapi:2.10.9'))
- //include(dependency('com.github.cryptomorin:XSeries:9.2.0'))
- include(dependency('com.github.cryptomorin:XSeries:9.0.0'))
+ include(dependency('com.github.cryptomorin:XSeries:9.2.0'))
+ //include(dependency('com.github.cryptomorin:XSeries:9.0.0'))
//include(dependency('com.github.cryptomorin:XSeries:8.8.0'))
include(dependency('de.tr7zw:item-nbt-api-plugin:2.11.1'))
From e4d2af08a23adc3e52e300894e45247355b3603e Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Thu, 29 Dec 2022 13:29:57 -0500
Subject: [PATCH 075/129] Added the tracking of command run times to the
`/prison support cmdStats`.
---
docs/changelog_v3.3.x.md | 4 +++
.../tech/mcprison/prison/PrisonCommand.java | 33 ++++++++++++++-----
.../prison/commands/RegisteredCommand.java | 28 ++++++++++++++--
3 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index b6bc080d0..ce997a14d 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -12,6 +12,10 @@ These build logs represent the work that has been going on within prison.
# 3.3.0-alpha.13g 2022-12-29
+
+* **Added the tracking of command run times to the `/prison support cmdStats`.**
+
+
* **Update various libraries used in the gradle build:**
placeholderApi: v2.10.9 to v2.11.2
XSeries: v9.0.0 to v9.2.0
diff --git a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
index 398366e63..d67b2b543 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/PrisonCommand.java
@@ -1174,29 +1174,46 @@ public void statsCommand(CommandSender sender ) {
private List getCommandStats() {
List results = new ArrayList<>();
- DecimalFormat dFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat iFmt = Prison.get().getDecimalFormatInt();
+ DecimalFormat dFmt = Prison.get().getDecimalFormatDouble();
TreeSet allCmds = Prison.get().getCommandHandler().getAllRegisteredCommands();
- results.add( "Prison Command Statss:" );
+ results.add( "Prison Command Stats:" );
+ results.add(
+ Output.stringFormat( " &a&n%-40s&r &a&n%7s&r &a&n%-11s&r",
+ " Commands ", " Usage ", " Avg ms ") );
int count = 0;
int totals = 0;
+ double totalDuration = 0d;
for (RegisteredCommand cmd : allCmds) {
if ( cmd.getUsageCount() > 0 ) {
- results.add( Output.stringFormat( " &3/%-40s &7%7s",
+
+ double duration = cmd.getUsageRunTimeNanos() / (double) cmd.getUsageCount() / 1000000.0d;
+
+ results.add( Output.stringFormat( " &2%-40s &2%7s &2%11s",
cmd.getCompleteLabel(),
- dFmt.format( cmd.getUsageCount() )) );
+ iFmt.format( cmd.getUsageCount() ),
+ dFmt.format( duration )
+ ) );
count++;
totals += cmd.getUsageCount();
+ totalDuration += cmd.getUsageRunTimeNanos();
}
}
- results.add( Output.stringFormat(" &3Total Registered Prison Commands: &7%9s", dFmt.format( allCmds.size() )) );
- results.add( Output.stringFormat(" &3Total Prison Commands Listed: &7%9s", dFmt.format( count )) );
- results.add( Output.stringFormat(" &3Total Prison Command Usage: &7%9s", dFmt.format( totals )) );
-
+ results.add( Output.stringFormat(" &3Total Registered Prison Commands: &7%9s", iFmt.format( allCmds.size() )) );
+ results.add( Output.stringFormat(" &3Total Prison Commands Listed: &7%9s", iFmt.format( count )) );
+ results.add( Output.stringFormat(" &3Total Prison Command Usage: &7%9s", iFmt.format( totals )) );
+
+ double avgDuration = totalDuration / (double) count / 1000000.0d;
+ results.add( Output.stringFormat(" &3Average Command Duration ms: &7%9s", dFmt.format( avgDuration )) );
+
+ results.add( " &d&oNOTE: Async Commands like '/mines reset' will not show actual runtime values. " );
+
+
return results;
}
diff --git a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
index 17265b686..f8deaecf7 100644
--- a/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
+++ b/prison-core/src/main/java/tech/mcprison/prison/commands/RegisteredCommand.java
@@ -43,6 +43,7 @@ public class RegisteredCommand
private boolean alias = false;
private int usageCount;
+ private long usageRunTimeNanos;
private String junitTest = null;
@@ -82,6 +83,7 @@ public RegisteredCommand(String label, CommandHandler handler, RegisteredCommand
this.registeredAliases = new ArrayList<>();
this.usageCount = 0;
+ this.usageRunTimeNanos = 0;
}
/**
@@ -220,6 +222,9 @@ private void executeMethod(CommandSender sender, String[] args ) {
ArrayList