Fix logic

This commit is contained in:
NotAlexNoyle committed 2026-08-17 10:44:08 -04:00
1 parent 2c09c3a6ea
commit 3f6d7bbca2
39 files changed
+263 -1534

No files matched your search

@@ -3,9 +3,6 @@
*/
package me.eccentric_nz.gamemodeinventories;
/**
* @author eccentric_nz
*/
public enum GMIDebug {
ERROR, INFO, ALL
}
@@ -242,9 +242,6 @@ public class GameModeInventories extends JavaPlugin {
}
/**
* Sets up the database.
*/
private void loadDatabase() {
String dbtype = getConfig().getString("storage.database");
@@ -305,9 +302,7 @@ public class GameModeInventories extends JavaPlugin {
}
/**
* Loads block logger support if available
*/
// Loads block logger support if available.
public void setUpBlockLogger() {
blockLogger = new GameModeInventoriesBlockLogger(this);
@@ -321,9 +316,8 @@ public class GameModeInventories extends JavaPlugin {
}
// The gamemode rules this server enforces. Also registered with the Bukkit
// services manager; plugins that cannot compile against this one reach it
// reflectively through this getter.
// The gamemode rules this server enforces; also on the services manager, and
// plugins that cannot compile against this one reach it via this getter.
public GameModePolicy getGameModePolicy() {
return gameModePolicy;
@@ -13,9 +13,6 @@ import me.eccentric_nz.gamemodeinventories.database.GameModeInventoriesMySQLConn
import me.eccentric_nz.gamemodeinventories.database.GameModeInventoriesQueueData;
import me.eccentric_nz.gamemodeinventories.database.GameModeInventoriesRecordingQueue;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBlock {
private final GameModeInventories plugin;
@@ -21,9 +21,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBlockListener implements Listener {
private final GameModeInventories plugin;
@@ -8,9 +8,6 @@ import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
import org.bukkit.plugin.PluginManager;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBlockLogger {
private final GameModeInventories plugin;
@@ -26,9 +26,6 @@ import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBukkitSerialization {
public static String toDatabase(ItemStack[] inventory) {
@@ -36,7 +33,6 @@ public class GameModeInventoriesBukkitSerialization {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Write the size of the inventory
try (BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream)) {
// Write the size of the inventory
@@ -52,7 +48,6 @@ public class GameModeInventoriesBukkitSerialization {
SkullMeta skullMeta = (SkullMeta) is.getItemMeta();
if (skullMeta.getOwnerProfile() == null) {
// remove item meta
is.setItemMeta(null);
}
@@ -65,7 +60,6 @@ public class GameModeInventoriesBukkitSerialization {
}
// Serialize that array
}
return Base64Coder.encodeLines(outputStream.toByteArray());
@@ -5,9 +5,6 @@ package me.eccentric_nz.gamemodeinventories;
import org.bukkit.entity.Player;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBypass {
public static boolean canBypass(Player p, String bypass, GameModeInventories plugin) {
@@ -10,9 +10,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.world.ChunkLoadEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesChunkLoadListener implements Listener {
private final GameModeInventories plugin;
@@ -10,9 +10,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesCommandListener implements Listener {
private final GameModeInventories plugin;
@@ -12,10 +12,8 @@ import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
// Checks the deployed config.yml against the canonical one bundled in the jar.
// There is no defaults map: the bundled file is the only description of what
// this plugin reads, so options cannot go missing from it or drift out of step
// with a second copy in code. Nothing is written back, ever.
// Checks the deployed config.yml against the canonical one bundled in the jar; there is no defaults
// map, so the bundled file is the only description of what this plugin reads. Nothing is written back, ever.
public class GameModeInventoriesConfig {
private final GameModeInventories plugin;
@@ -77,11 +77,7 @@ public class GameModeInventoriesDeath implements Listener {
}
/**
* Gets the server values for force-gamemode and gamemode.
*
* @return whether the value is true or false.
*/
// reads force-gamemode and gamemode from server.properties
private ServerValues getServerForceGamemode() {
FileInputStream in = null;
@@ -16,9 +16,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesEntityListener implements Listener {
private final GameModeInventories plugin;
@@ -357,7 +357,6 @@ public class GameModeInventoriesInventory {
String uuid = p.getUniqueId().toString();
String gm = p.getGameMode().name();
// restore their inventory
try (Connection connection = plugin.getDatabaseConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM " + plugin.getPrefix() + "inventories WHERE uuid = ? AND gamemode = ?");)
@@ -26,11 +26,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.inventory.ItemStack;
/**
* Fancy JSON serialization mostly by evilmidget38.
*
* @author eccentric_nz
*/
// Fancy JSON serialization mostly by evilmidget38.
public class GameModeInventoriesJSONSerialization {
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
@@ -77,9 +77,8 @@ public class GameModeInventoriesListener implements Listener {
Player p = event.getPlayer();
GameMode newGM = event.getNewGameMode();
// Internal switches (/gmic, the policy's changeGameMode) are
// pre-validated by their callers and trusted here; only external
// routes (/gamemode, other plugins) are policed and told why.
// Internal switches (/gmic, the policy's changeGameMode) are pre-validated
// and trusted; only external routes (/gamemode, other plugins) are policed.
boolean internal = plugin.isInternalGameModeChange(p);
if (!internal && newGM.equals(GameMode.CREATIVE) && !canUseCreativeAt(p, modeCheckLocation(p))) {
@@ -230,9 +229,8 @@ public class GameModeInventoriesListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
// Spawn-OG normalizes logins inside a safety transaction that also relocates
// the player. Forcing survival underneath it would race that transaction, so
// this handler only covers servers running without it.
// Spawn-OG normalizes logins in a transaction that also relocates; forcing
// survival underneath would race it, so this only covers servers without it.
if (plugin.getServer().getPluginManager().isPluginEnabled("Spawn-OG")) {
return;
@@ -17,9 +17,6 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesMessage {
// Matches the colour codes of messages.yml files predating the MiniMessage
@@ -208,7 +205,6 @@ public class GameModeInventoriesMessage {
public void updateMessages() {
// message values
int m = 0;
for (Map.Entry<String, String> entry : messageOptions.entrySet()) {
@@ -12,9 +12,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesPhysicsListener implements Listener {
private final GameModeInventories plugin;
@@ -12,9 +12,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesPistonListener implements Listener {
private final GameModeInventories plugin;
@@ -10,9 +10,6 @@ import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Level;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesStand {
private final GameModeInventories plugin;
@@ -17,9 +17,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesTrackBlackListener implements Listener {
private final GameModeInventories plugin;
@@ -78,7 +75,7 @@ public class GameModeInventoriesTrackBlackListener implements Listener {
if (plugin.getConfig().getBoolean("track_creative_place.break_no_drop")) {
// remove the location from the creative blocks list because we're removing the
// block!
// block
plugin.getBlock().removeBlock(gmiwc, block.getLocation().toString());
if (plugin.getBlockLogger().isLogging()) {
@@ -17,9 +17,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesTrackWhiteListener implements Listener {
private final GameModeInventories plugin;
@@ -74,7 +71,7 @@ public class GameModeInventoriesTrackWhiteListener implements Listener {
if (plugin.getConfig().getBoolean("track_creative_place.break_no_drop")) {
// remove the location from the creative blocks list because we're removing the
// block!
// block
plugin.getBlock().removeBlock(gmiwc, block.getLocation().toString());
if (plugin.getBlockLogger().isLogging()) {
@@ -16,9 +16,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesWorldListener implements Listener {
private final GameModeInventories plugin;
@@ -32,37 +29,8 @@ public class GameModeInventoriesWorldListener implements Listener {
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
// if (plugin.getConfig().getBoolean("creative_world.switch_to")) {
// Player p = event.getPlayer();
// String uuid = p.getUniqueId().toString();
// // player changed worlds, record last location
// // check if the player has a record for this world
// try (
// Connection connection = GameModeInventoriesConnectionPool.dbc();
// PreparedStatement statement = connection.prepareStatement("SELECT * FROM
// worlds WHERE uuid
// = ? AND world = ?");
// ) {
// statement.setString(1, uuid);
// statement.setString(2, p.getWorld().getName());
// try (ResultSet rs = statement.executeQuery();) {
// if (rs.next()) {
// World w = plugin.getServer().getWorld(rs.getString("world"));
// if (w != null) {
// double x = rs.getDouble("x");
// double y = rs.getDouble("y");
// double z = rs.getDouble("z");
// float yaw = rs.getFloat("yaw");
// float pitch = rs.getFloat("pitch");
// Location loc = new Location(w, x, y, z, yaw, pitch);
// p.teleport(loc);
// }
// }
// }
// } catch (SQLException e) {
// plugin.debug("Could not get creative world location, " + e);
// }
// }
// Disabled feature: with creative_world.switch_to set, look up the player's
// saved location for this world and teleport them back to it.
if (!plugin.getConfig().getBoolean("survival_on_world_change")) {
return;
@@ -5,20 +5,8 @@ import java.lang.ref.WeakReference;
import java.util.Arrays;
import org.bukkit.entity.Player;
/**
* @author desht
* <p>
* Adapted from ExperienceUtils code originally in ScrollingMenuSign.
* <p>
* Credit to nisovin
* (http://forums.bukkit.org/threads/experienceutils-make-giving-taking-exp-a-bit-more-intuitive.54450/#post-1067480)
* for an implementation that avoids the problems of
* getTotalExperience(), which doesn't work properly after a player has
* enchanted something.
* <p>
* Credit to comphenix for further contributions: See
* http://forums.bukkit.org/threads/experiencemanager-was-experienceutils-make-giving-taking-exp-a-bit-more-intuitive.54450/page-3#post-1273622
*/
// By desht, adapted from ExperienceUtils (ScrollingMenuSign); credit to nisovin and comphenix
// for an approach that avoids getTotalExperience(), which breaks after a player enchants.
public class GameModeInventoriesXPCalculator {
// this is to stop the lookup table growing without control
@@ -37,12 +25,6 @@ public class GameModeInventoriesXPCalculator {
private final WeakReference<Player> player;
private final String playerName;
/**
* Create a new GameModeInventoriesXPCalculator for the given player.
*
* @param player the player for this GameModeInventoriesXPCalculator object
* @throws IllegalArgumentException if the player is null
*/
GameModeInventoriesXPCalculator(Player player) {
Preconditions.checkNotNull(player, "Player cannot be null");
@@ -51,33 +33,19 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Get the current hard max level for which calculations will be done.
*
* @return the current hard max level
*/
public static int getHardMaxLevel() {
return hardMaxLevel;
}
/**
* Set the current hard max level for which calculations will be done.
*
* @param hardMaxLevel the new hard max level
*/
public static void setHardMaxLevel(int hardMaxLevel) {
GameModeInventoriesXPCalculator.hardMaxLevel = hardMaxLevel;
}
/**
* Initialize the XP lookup table. See http://minecraft.gamepedia.com/Experience
*
* @param maxLevel The highest level handled by the lookup tables
*/
// XP formulas from http://minecraft.gamepedia.com/Experience
private static void initLookupTables(int maxLevel) {
xpTotalToReachLevel = new int[maxLevel];
@@ -91,14 +59,8 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Calculate the level that the given XP quantity corresponds to, without using
* the lookup tables. This is needed if getLevelForExp() is called with an XP
* quantity beyond the range of the existing lookup tables.
*
* @param exp
* @return
*/
// Calculates the level for an XP quantity without the lookup tables, for
// getLevelForExp() calls with XP beyond the range of the existing tables.
private static int calculateLevelForExp(int exp) {
int level = 0;
@@ -117,12 +79,7 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Get the Player associated with this GameModeInventoriesXPCalculator.
*
* @return the Player object
* @throws IllegalStateException if the player is no longer online
*/
// Throws IllegalStateException if the player is no longer online.
public Player getPlayer() {
Player p = player.get();
@@ -136,48 +93,29 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Adjust the player's XP by the given amount in an intelligent fashion. Works
* around some of the non-intuitive behaviour of the basic Bukkit
* player.giveExp() method.
*
* @param amt Amount of XP, may be negative
*/
// Adjusts the player's XP by the given amount (may be negative); works around
// non-intuitive behaviour of the basic Bukkit player.giveExp() method.
public void changeExp(int amt) {
changeExp((double) amt);
}
/**
* Adjust the player's XP by the given amount in an intelligent fashion. Works
* around some of the non-intuitive behaviour of the basic Bukkit
* player.giveExp() method.
*
* @param amt Amount of XP, may be negative
*/
// As changeExp(int), for fractional amounts.
private void changeExp(double amt) {
setExp(getCurrentFractionalXP(), amt);
}
/**
* Set the player's experience
*
* @param amt Amount of XP, should not be negative
*/
// Sets the player's experience; amount should not be negative.
void setExp(int amt) {
setExp(0, amt);
}
/**
* Set the player's fractional experience.
*
* @param amt Amount of XP, should not be negative
*/
// Sets the player's fractional experience; amount should not be negative.
public void setExp(double amt) {
setExp(0, amt);
@@ -192,7 +130,6 @@ public class GameModeInventoriesXPCalculator {
int curLvl = p.getLevel();
int newLvl = getLevelForExp(xp);
// Increment level
if (curLvl != newLvl) {
p.setLevel(newLvl);
@@ -207,11 +144,6 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Get the player's current XP total.
*
* @return the player's total XP
*/
int getCurrentExp() {
Player p = getPlayer();
@@ -222,11 +154,6 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Get the player's current fractional XP.
*
* @return The player's total XP with fractions.
*/
private double getCurrentFractionalXP() {
Player p = getPlayer();
@@ -237,37 +164,19 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Checks if the player has the given amount of XP.
*
* @param amt The amount to check for.
* @return true if the player has enough XP, false otherwise
*/
public boolean hasExp(int amt) {
return getCurrentExp() >= amt;
}
/**
* Checks if the player has the given amount of fractional XP.
*
* @param amt The amount to check for.
* @return true if the player has enough XP, false otherwise
*/
public boolean hasExp(double amt) {
return getCurrentFractionalXP() >= amt;
}
/**
* Get the level that the given amount of XP falls within.
*
* @param exp the amount to check for
* @return the level that a player with this amount total XP would be
* @throws IllegalArgumentException if the given XP is less than 0
*/
// Returns the level that a player with this amount of total XP would be.
private int getLevelForExp(int exp) {
if (exp <= 0) {
@@ -291,14 +200,7 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Retrieves the amount of experience the experience bar can hold at the given
* level.
*
* @param level the level to check
* @return the amount of experience at this level in the level bar
* @throws IllegalArgumentException if the level is less than 0
*/
// Amount of experience the XP bar can hold at the given level.
private int getXpNeededToLevelUp(int level) {
Preconditions.checkArgument(level >= 0, "Level may not be negative.");
@@ -306,14 +208,7 @@ public class GameModeInventoriesXPCalculator {
}
/**
* Return the total XP needed to be the given level.
*
* @param level The level to check for.
* @return The amount of XP needed for the level.
* @throws IllegalArgumentException if the level is less than 0 or greater than
* the current hard maximum
*/
// Total XP needed to reach the given level.
private int getXpForLevel(int level) {
Preconditions.checkArgument(level >= 0 && level <= hardMaxLevel,
@@ -33,72 +33,19 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
/**
* A JSONArray is an ordered sequence of values. Its external text form is a
* string wrapped in square brackets with commas separating the values. The
* internal form is an object having <code>get</code> and <code>opt</code>
* methods for accessing the values by index, and <code>put</code> methods for
* adding or replacing values. The values can be any of these types:
* <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
* <code>Number</code>, <code>String</code>, or the
* <code>JSONObject.NULL object</code>.
* <p>
* The constructor can convert a JSON text into a Java object. The
* <code>toString</code> method converts to JSON text.
* <p>
* A <code>get</code> method returns a value if one can be found, and throws an
* exception if one cannot be found. An <code>opt</code> method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
* <p>
* The generic <code>get()</code> and <code>opt()</code> methods return an
* object which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and type
* coercion for you.
* <p>
* The texts produced by the <code>toString</code> methods strictly conform to
* JSON syntax rules. The constructors are more forgiving in the texts they will
* accept:
* <ul>
* <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear just
* before the closing bracket.</li>
* <li>The <code>null</code> value will be inserted when there is <code>,</code>
* &nbsp;<small>(comma)</small> elision.</li>
* <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single
* quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces, and
* if they do not contain any of these characters:
* <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and if
* they are not the reserved words <code>true</code>, <code>false</code>, or
* <code>null</code>.</li>
* </ul>
*
* @author JSON.org
* @version 2013-04-18
*/
// An ordered sequence of values whose external form is JSON text in square brackets.
// get methods throw if a value is missing; opt methods return a default instead.
public class JSONArray {
/**
* The arrayList where the JSONArray's properties are kept.
*/
private final ArrayList myArrayList;
/**
* Construct an empty JSONArray.
*/
public JSONArray() {
this.myArrayList = new ArrayList();
}
/**
* Construct a JSONArray from a JSONTokener.
*
* @param x A JSONTokener
* @throws JSONException If there is a syntax error.
*/
// Construct a JSONArray from a JSONTokener; throws on syntax error.
public JSONArray(JSONTokener x) throws JSONException {
this();
@@ -148,25 +95,13 @@ public class JSONArray {
}
/**
* Construct a JSONArray from a source JSON text.
*
* @param source A string that begins with <code>[</code>&nbsp;<small>(left
* bracket)</small> and ends with <code>]</code>
* &nbsp;<small>(right bracket)</small>.
* @throws JSONException If there is a syntax error.
*/
// Construct a JSONArray from a source JSON text; throws on syntax error.
public JSONArray(String source) throws JSONException {
this(new JSONTokener(source));
}
/**
* Construct a JSONArray from a Collection.
*
* @param collection A Collection.
*/
public JSONArray(Collection collection) {
this.myArrayList = new ArrayList();
@@ -183,12 +118,7 @@ public class JSONArray {
}
/**
* Construct a JSONArray from an array
*
* @param array
* @throws JSONException If not an array.
*/
// Construct a JSONArray from an array; throws if the argument is not an array.
public JSONArray(Object array) throws JSONException {
this();
@@ -209,13 +139,7 @@ public class JSONArray {
}
/**
* Get the object value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return An object value.
* @throws JSONException If there is no value for the index.
*/
// Get the object value at an index; throws if there is no value for the index.
public Object get(int index) throws JSONException {
Object object = this.opt(index);
@@ -229,15 +153,8 @@ public class JSONArray {
}
/**
* Get the boolean value associated with an index. The string values "true" and
* "false" are converted to boolean.
*
* @param index The index must be between 0 and length() - 1.
* @return The truth.
* @throws JSONException If there is no value for the index or if the value is
* not convertible to boolean.
*/
// Get the boolean value at an index. The strings "true" and "false"
// (case insensitive) are converted; throws if not convertible to boolean.
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
@@ -257,14 +174,8 @@ public class JSONArray {
}
/**
* Get the double value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot be
* converted to a number.
*/
// Get the double value at an index; throws if the value cannot be converted to
// a number.
public double getDouble(int index) throws JSONException {
Object object = this.get(index);
@@ -280,14 +191,8 @@ public class JSONArray {
}
/**
* Get the int value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value is not a
* number.
*/
// Get the int value at an index; throws if the value cannot be converted to a
// number.
public int getInt(int index) throws JSONException {
Object object = this.get(index);
@@ -303,14 +208,7 @@ public class JSONArray {
}
/**
* Get the JSONArray associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return A JSONArray value.
* @throws JSONException If there is no value for the index. or if the value is
* not a JSONArray
*/
// Get the JSONArray at an index; throws if the value is not a JSONArray.
public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
@@ -324,14 +222,7 @@ public class JSONArray {
}
/**
* Get the JSONObject associated with an index.
*
* @param index subscript
* @return A JSONObject value.
* @throws JSONException If there is no value for the index or if the value is
* not a JSONObject
*/
// Get the JSONObject at an index; throws if the value is not a JSONObject.
public JSONObject getJSONObject(int index) throws JSONException {
Object object = this.get(index);
@@ -345,14 +236,8 @@ public class JSONArray {
}
/**
* Get the long value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot be
* converted to a number.
*/
// Get the long value at an index; throws if the value cannot be converted to a
// number.
public long getLong(int index) throws JSONException {
Object object = this.get(index);
@@ -368,14 +253,8 @@ public class JSONArray {
}
/**
* Get the byte value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot be
* converted to a number.
*/
// Get the byte value at an index; throws if the value cannot be converted to a
// number.
public byte getByte(int index) throws JSONException {
Object object = this.get(index);
@@ -391,13 +270,7 @@ public class JSONArray {
}
/**
* Get the string associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return A string value.
* @throws JSONException If there is no string value for the index.
*/
// Get the string at an index; throws if there is no string value.
public String getString(int index) throws JSONException {
Object object = this.get(index);
@@ -411,27 +284,15 @@ public class JSONArray {
}
/**
* Determine if the value is null.
*
* @param index The index must be between 0 and length() - 1.
* @return true if the value at the index is null, or if there is no value.
*/
// Returns true if the value at the index is null, or if there is no value.
public boolean isNull(int index) {
return JSONObject.NULL.equals(this.opt(index));
}
/**
* Make a string from the contents of this JSONArray. The <code>separator</code>
* string is inserted between each element. Warning: This method assumes that
* the data structure is acyclical.
*
* @param separator A string that will be inserted between the elements.
* @return a string.
* @throws JSONException If the array contains an invalid number.
*/
// Join the elements into a string with separator between them.
// Assumes the data structure is acyclical; throws on an invalid number.
public String join(String separator) throws JSONException {
int len = this.length();
@@ -453,52 +314,31 @@ public class JSONArray {
}
/**
* Get the number of elements in the JSONArray, included nulls.
*
* @return The length (or size).
*/
// Get the number of elements in the JSONArray, including nulls.
public int length() {
return this.myArrayList.size();
}
/**
* Get the optional object value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return An object value, or null if there is no object at that index.
*/
// Get the object value at an index, or null if there is no object at that
// index.
public Object opt(int index) {
return (index < 0 || index >= this.length()) ? null : this.myArrayList.get(index);
}
/**
* Get the optional boolean value associated with an index. It returns false if
* there is no value at that index, or if the value is not Boolean.TRUE or the
* String "true".
*
* @param index The index must be between 0 and length() - 1.
* @return The truth.
*/
// Get the optional boolean at an index; false if missing or not convertible to
// boolean.
public boolean optBoolean(int index) {
return this.optBoolean(index, false);
}
/**
* Get the optional boolean value associated with an index. It returns the
* defaultValue if there is no value at that index or if it is not a Boolean or
* the String "true" or "false" (case insensitive).
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue A boolean default.
* @return The truth.
*/
// Get the optional boolean at an index; defaultValue if missing or not
// convertible.
public boolean optBoolean(int index, boolean defaultValue) {
try {
@@ -513,29 +353,16 @@ public class JSONArray {
}
/**
* Get the optional double value associated with an index. NaN is returned if
* there is no value for the index, or if the value is not a number and cannot
* be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
// Get the optional double at an index; NaN if missing or not convertible to a
// number.
public double optDouble(int index) {
return this.optDouble(index, Double.NaN);
}
/**
* Get the optional double value associated with an index. The defaultValue is
* returned if there is no value for the index, or if the value is not a number
* and cannot be converted to a number.
*
* @param index subscript
* @param defaultValue The default value.
* @return The value.
*/
// Get the optional double at an index; defaultValue if missing or not
// convertible.
public double optDouble(int index, double defaultValue) {
try {
@@ -550,29 +377,15 @@ public class JSONArray {
}
/**
* Get the optional int value associated with an index. Zero is returned if
* there is no value for the index, or if the value is not a number and cannot
* be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
// Get the optional int at an index; zero if missing or not convertible to a
// number.
public int optInt(int index) {
return this.optInt(index, 0);
}
/**
* Get the optional int value associated with an index. The defaultValue is
* returned if there is no value for the index, or if the value is not a number
* and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
// Get the optional int at an index; defaultValue if missing or not convertible.
public int optInt(int index, int defaultValue) {
try {
@@ -587,13 +400,7 @@ public class JSONArray {
}
/**
* Get the optional JSONArray associated with an index.
*
* @param index subscript
* @return A JSONArray value, or null if the index has no value, or if the value
* is not a JSONArray.
*/
// Get the optional JSONArray at an index, or null if there is none.
public JSONArray optJSONArray(int index) {
Object o = this.opt(index);
@@ -601,14 +408,7 @@ public class JSONArray {
}
/**
* Get the optional JSONObject associated with an index. Null is returned if the
* key is not found, or null if the index has no value, or if the value is not a
* JSONObject.
*
* @param index The index must be between 0 and length() - 1.
* @return A JSONObject value.
*/
// Get the optional JSONObject at an index, or null if there is none.
public JSONObject optJSONObject(int index) {
Object o = this.opt(index);
@@ -616,29 +416,16 @@ public class JSONArray {
}
/**
* Get the optional long value associated with an index. Zero is returned if
* there is no value for the index, or if the value is not a number and cannot
* be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
// Get the optional long at an index; zero if missing or not convertible to a
// number.
public long optLong(int index) {
return this.optLong(index, 0);
}
/**
* Get the optional long value associated with an index. The defaultValue is
* returned if there is no value for the index, or if the value is not a number
* and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
// Get the optional long at an index; defaultValue if missing or not
// convertible.
public long optLong(int index, long defaultValue) {
try {
@@ -653,28 +440,15 @@ public class JSONArray {
}
/**
* Get the optional string value associated with an index. It returns an empty
* string if there is no value at that index. If the value is not a string and
* is not null, then it is coverted to a string.
*
* @param index The index must be between 0 and length() - 1.
* @return A String value.
*/
// Get the optional string at an index; empty string if there is no value.
// Non-null, non-string values are converted to a string.
public String optString(int index) {
return this.optString(index, "");
}
/**
* Get the optional string associated with an index. The defaultValue is
* returned if the key is not found.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return A String value.
*/
// Get the optional string at an index, or defaultValue if there is no value.
public String optString(int index, String defaultValue) {
Object object = this.opt(index);
@@ -682,12 +456,7 @@ public class JSONArray {
}
/**
* Append a boolean value. This increases the array's length by one.
*
* @param value A boolean value.
* @return this.
*/
// Append a boolean value.
public JSONArray put(boolean value) {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
@@ -695,13 +464,7 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONArray which is
* produced from a Collection.
*
* @param value A Collection value.
* @return this.
*/
// Append a Collection value, which is wrapped as a JSONArray.
public JSONArray put(Collection value) {
this.put(new JSONArray(value));
@@ -709,13 +472,7 @@ public class JSONArray {
}
/**
* Append a double value. This increases the array's length by one.
*
* @param value A double value.
* @return this.
* @throws JSONException if the value is not finite.
*/
// Append a double value; throws if it is not finite.
public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
@@ -725,12 +482,7 @@ public class JSONArray {
}
/**
* Append an int value. This increases the array's length by one.
*
* @param value An int value.
* @return this.
*/
// Append an int value.
public JSONArray put(int value) {
this.put(new Integer(value));
@@ -738,12 +490,7 @@ public class JSONArray {
}
/**
* Append an long value. This increases the array's length by one.
*
* @param value A long value.
* @return this.
*/
// Append a long value.
public JSONArray put(long value) {
this.put(new Long(value));
@@ -751,13 +498,7 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONObject which is
* produced from a Map.
*
* @param value A Map value.
* @return this.
*/
// Append a Map value, which is wrapped as a JSONObject.
public JSONArray put(Map value) {
this.put(new JSONObject(value));
@@ -765,14 +506,8 @@ public class JSONArray {
}
/**
* Append an object value. This increases the array's length by one.
*
* @param value An object value. The value should be a Boolean, Double, Integer,
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL
* object.
* @return this.
*/
// Append an object value: a Boolean, Double, Integer, JSONArray, JSONObject,
// Long, or String, or the JSONObject.NULL object.
public JSONArray put(Object value) {
this.myArrayList.add(value);
@@ -780,16 +515,8 @@ public class JSONArray {
}
/**
* Put or replace a boolean value in the JSONArray. If the index is greater than
* the length of the JSONArray, then null elements will be added as necessary to
* pad it out.
*
* @param index The subscript.
* @param value A boolean value.
* @return this.
* @throws JSONException If the index is negative.
*/
// Put or replace a boolean at an index; pads with nulls if the index exceeds
// the length.
public JSONArray put(int index, boolean value) throws JSONException {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
@@ -797,15 +524,7 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONArray which is
* produced from a Collection.
*
* @param index The subscript.
* @param value A Collection value.
* @return this.
* @throws JSONException If the index is negative or if the value is not finite.
*/
// Put a Collection at an index, wrapped as a JSONArray.
public JSONArray put(int index, Collection value) throws JSONException {
this.put(index, new JSONArray(value));
@@ -813,15 +532,8 @@ public class JSONArray {
}
/**
* Put or replace a double value. If the index is greater than the length of the
* JSONArray, then null elements will be added as necessary to pad it out.
*
* @param index The subscript.
* @param value A double value.
* @return this.
* @throws JSONException If the index is negative or if the value is not finite.
*/
// Put or replace a double at an index; pads with nulls if the index exceeds the
// length.
public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
@@ -829,15 +541,8 @@ public class JSONArray {
}
/**
* Put or replace an int value. If the index is greater than the length of the
* JSONArray, then null elements will be added as necessary to pad it out.
*
* @param index The subscript.
* @param value An int value.
* @return this.
* @throws JSONException If the index is negative.
*/
// Put or replace an int at an index; pads with nulls if the index exceeds the
// length.
public JSONArray put(int index, int value) throws JSONException {
this.put(index, new Integer(value));
@@ -845,15 +550,8 @@ public class JSONArray {
}
/**
* Put or replace a long value. If the index is greater than the length of the
* JSONArray, then null elements will be added as necessary to pad it out.
*
* @param index The subscript.
* @param value A long value.
* @return this.
* @throws JSONException If the index is negative.
*/
// Put or replace a long at an index; pads with nulls if the index exceeds the
// length.
public JSONArray put(int index, long value) throws JSONException {
this.put(index, new Long(value));
@@ -861,16 +559,7 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONObject that is
* produced from a Map.
*
* @param index The subscript.
* @param value The Map value.
* @return this.
* @throws JSONException If the index is negative or if the the value is an
* invalid number.
*/
// Put a Map at an index, wrapped as a JSONObject.
public JSONArray put(int index, Map value) throws JSONException {
this.put(index, new JSONObject(value));
@@ -878,19 +567,8 @@ public class JSONArray {
}
/**
* Put or replace an object value in the JSONArray. If the index is greater than
* the length of the JSONArray, then null elements will be added as necessary to
* pad it out.
*
* @param index The subscript.
* @param value The value to put into the array. The value should be a Boolean,
* Double, Integer, JSONArray, JSONObject, Long, or String, or the
* JSONObject.NULL object.
* @return this.
* @throws JSONException If the index is negative or if the the value is an
* invalid number.
*/
// Put or replace an object value at an index. If the index exceeds the length,
// null elements are added to pad it out; throws if the index is negative.
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
@@ -920,13 +598,8 @@ public class JSONArray {
}
/**
* Remove an index and close the hole.
*
* @param index The index of the element to be removed.
* @return The value that was associated with the index, or null if there was no
* value.
*/
// Remove the element at an index and close the hole.
// Returns the removed value, or null if there was none.
public Object remove(int index) {
Object o = this.opt(index);
@@ -935,16 +608,8 @@ public class JSONArray {
}
/**
* Produce a JSONObject by combining a JSONArray of names with the values of
* this JSONArray.
*
* @param names A JSONArray containing a list of key strings. These will be
* paired with the values.
* @return A JSONObject, or null if there are no names or if this JSONArray has
* no values.
* @throws JSONException If any of the names are null.
*/
// Produce a JSONObject pairing the given names with this array's values.
// Returns null if either array is empty; throws if any name is null.
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0) {
@@ -964,16 +629,8 @@ public class JSONArray {
}
/**
* Make a JSON text of this JSONArray. For compactness, no unnecessary
* whitespace is added. If it is not possible to produce a syntactically correct
* JSON text then null will be returned instead. This could occur if the array
* contains an invalid number.
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
* @return a printable, displayable, transmittable representation of the array.
*/
// Make a compact JSON text of this JSONArray. Returns null if a syntactically
// correct text cannot be produced. Assumes the data structure is acyclical.
@Override
public String toString() {
@@ -989,16 +646,8 @@ public class JSONArray {
}
/**
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
* assumes that the data structure is acyclical.
*
* @param indentFactor The number of spaces to add to each level of indentation.
* @return a printable, displayable, transmittable representation of the object,
* beginning with <code>[</code>&nbsp;<small>(left bracket)</small> and
* ending with <code>]</code> &nbsp;<small>(right bracket)</small>.
* @throws JSONException
*/
// Make a prettyprinted JSON text of this JSONArray. Assumes the data structure
// is acyclical.
public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
@@ -1010,33 +659,16 @@ public class JSONArray {
}
/**
* Write the contents of the JSONArray as JSON text to a writer. For
* compactness, no whitespace is added.
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
* @param writer
* @return The writer.
* @throws JSONException
*/
// Write the contents as compact JSON text to a writer. Assumes the data
// structure is acyclical.
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
/**
* Write the contents of the JSONArray as JSON text to a writer. For
* compactness, no whitespace is added.
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
* @param indentFactor The number of spaces to add to each level of indentation.
* @param indent The indention of the top level.
* @return The writer.
* @throws JSONException
*/
// Write the contents as JSON text to a writer, with the given indentation.
// Assumes the data structure is acyclical.
Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
try {
@@ -1,32 +1,17 @@
package me.eccentric_nz.gamemodeinventories.JSON;
/**
* The JSONException is thrown by the JSON.org classes when things are amiss.
*
* @author JSON.org
* @version 2013-02-10
*/
// Thrown by the JSON.org classes when things are amiss.
public class JSONException extends RuntimeException {
private static final long serialVersionUID = 0;
private Throwable cause;
/**
* Constructs a JSONException with an explanatory message.
*
* @param message Detail about the reason for the exception.
*/
public JSONException(String message) {
super(message);
}
/**
* Constructs a new JSONException with the specified cause.
*
* @param cause
*/
public JSONException(Throwable cause) {
super(cause.getMessage());
@@ -34,13 +19,8 @@ public class JSONException extends RuntimeException {
}
/**
* Returns the cause of this exception or null if the cause is nonexistent or
* unknown.
*
* @return the cause of this exception or null if the cause is nonexistent or
* unknown.
*/
// Returns the cause of this exception, or null if the cause is nonexistent or
// unknown.
@Override
public Throwable getCause() {
File diff suppressed because it is too large. Load diff
@@ -1,21 +1,10 @@
package me.eccentric_nz.gamemodeinventories.JSON;
/**
* The <code>JSONString</code> interface allows a <code>toJSONString()</code>
* method so that a class can change the behavior of
* <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>, and
* <code>JSONWriter.value(</code>Object<code>)</code>. The
* <code>toJSONString</code> method will be used instead of the default behavior
* of using the Object's <code>toString()</code> method and quoting the result.
*/
// Lets a class supply its own JSON serialization: toJSONString() is used by JSONObject.toString(),
// JSONArray.toString(), and JSONWriter.value(Object) instead of quoting the Object's toString().
public interface JSONString {
/**
* The <code>toJSONString</code> method allows a class to produce its own JSON
* serialization.
*
* @return A strictly syntactically correct JSON text.
*/
// Returns a strictly syntactically correct JSON text representing this object.
public String toJSONString();
}
@@ -26,14 +26,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* A JSONTokener takes a source string and extracts characters and tokens from
* it. It is used by the JSONObject and JSONArray constructors to parse JSON
* source strings.
*
* @author JSON.org
* @version 2012-02-16
*/
// Extracts characters and tokens from a source string. Used by the JSONObject
// and JSONArray constructors to parse JSON source strings.
public class JSONTokener {
private final Reader reader;
@@ -44,11 +38,6 @@ public class JSONTokener {
private char previous;
private boolean usePrevious;
/**
* Construct a JSONTokener from a Reader.
*
* @param reader A reader.
*/
public JSONTokener(Reader reader) {
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
@@ -61,35 +50,19 @@ public class JSONTokener {
}
/**
* Construct a JSONTokener from an InputStream.
*
* @param inputStream
*/
public JSONTokener(InputStream inputStream) throws JSONException {
this(new InputStreamReader(inputStream));
}
/**
* Construct a JSONTokener from a string.
*
* @param s A source string.
*/
public JSONTokener(String s) {
this(new StringReader(s));
}
/**
* Get the hex value of a character (base16).
*
* @param c A character between '0' and '9' or between 'A' and 'F' or between
* 'a' and 'f'.
* @return An int between 0 and 15, or -1 if c was not a hex digit.
*/
// Get the hex value of a character (base16), or -1 if c is not a hex digit.
public static int dehexchar(char c) {
if (c >= '0' && c <= '9') {
@@ -114,11 +87,8 @@ public class JSONTokener {
}
/**
* Back up one character. This provides a sort of lookahead capability, so that
* you can test for a digit or letter before attempting to parse the next number
* or identifier.
*/
// Back up one character to provide lookahead; stepping back twice is not
// supported.
public void back() throws JSONException {
if (usePrevious || index <= 0) {
@@ -140,12 +110,8 @@ public class JSONTokener {
}
/**
* Determine if the source string still contains characters that next() can
* consume.
*
* @return true if not yet at the end of the source.
*/
// Returns true if the source string still contains characters that next() can
// consume.
public boolean more() throws JSONException {
next();
@@ -160,11 +126,7 @@ public class JSONTokener {
}
/**
* Get the next character in the source string.
*
* @return The next character, or 0 if past the end of the source string.
*/
// Get the next character in the source string, or 0 if past the end.
public char next() throws JSONException {
int c;
@@ -216,13 +178,8 @@ public class JSONTokener {
}
/**
* Consume the next character, and check that it matches a specified character.
*
* @param c The character to match.
* @return The character.
* @throws JSONException if the character does not match.
*/
// Consume the next character and check that it matches c; throws if it does
// not.
public char next(char c) throws JSONException {
char n = next();
@@ -236,14 +193,8 @@ public class JSONTokener {
}
/**
* Get the next n characters.
*
* @param n The number of characters to take.
* @return A string of n characters.
* @throws JSONException Substring bounds error if there are not n characters
* remaining in the source string.
*/
// Get the next n characters; throws if fewer than n characters remain in the
// source.
public String next(int n) throws JSONException {
if (n == 0) {
@@ -272,12 +223,8 @@ public class JSONTokener {
}
/**
* Get the next char in the string, skipping whitespace.
*
* @return A character, or 0 if there are no more characters.
* @throws JSONException
*/
// Get the next character, skipping whitespace; 0 if there are no more
// characters.
public char nextClean() throws JSONException {
for (;;) {
@@ -293,17 +240,8 @@ public class JSONTokener {
}
/**
* Return the characters up to the next close quote character. Backslash
* processing is done. The formal JSON format does not allow strings in single
* quotes, but an implementation is allowed to accept them.
*
* @param quote The quoting character, either <code>"</code>&nbsp;<small>(double
* quote)</small> or <code>'</code>&nbsp;<small>(single
* quote)</small>.
* @return A String.
* @throws JSONException Unterminated string.
*/
// Return the characters up to the next close quote, processing backslash
// escapes. Single quotes are accepted even though formal JSON forbids them.
public String nextString(char quote) throws JSONException {
char c;
@@ -364,13 +302,7 @@ public class JSONTokener {
}
/**
* Get the text up but not including the specified character or the end of line,
* whichever comes first.
*
* @param delimiter A delimiter character.
* @return A string.
*/
// Get the text up to but not including the delimiter or end of line, trimmed.
public String nextTo(char delimiter) throws JSONException {
StringBuilder sb = new StringBuilder();
@@ -395,13 +327,8 @@ public class JSONTokener {
}
/**
* Get the text up but not including one of the specified delimiter characters
* or the end of line, whichever comes first.
*
* @param delimiters A set of delimiter characters.
* @return A string, trimmed.
*/
// Get the text up to but not including one of the delimiter characters
// or the end of line, trimmed.
public String nextTo(String delimiters) throws JSONException {
char c;
@@ -427,13 +354,8 @@ public class JSONTokener {
}
/**
* Get the next value. The value can be a Boolean, Double, Integer, JSONArray,
* JSONObject, Long, or String, or the JSONObject.NULL object.
*
* @return An object.
* @throws JSONException If syntax error.
*/
// Get the next value: a Boolean, Double, Integer, JSONArray, JSONObject, Long,
// or String, or the JSONObject.NULL object. Throws on syntax error.
public Object nextValue() throws JSONException {
char c = nextClean();
@@ -472,14 +394,8 @@ public class JSONTokener {
}
/**
* Skip characters until the next character is the requested character. If the
* requested character is not found, no characters are skipped.
*
* @param to A character to skip to.
* @return The requested character, or zero if the requested character is not
* found.
*/
// Skip characters until the next character is the requested character. Returns
// that character, or 0 (with no characters skipped) if it is not found.
public char skipTo(char to) throws JSONException {
char c;
@@ -515,23 +431,15 @@ public class JSONTokener {
}
/**
* Make a JSONException to signal a syntax error.
*
* @param message The error message.
* @return A JSONException object, suitable for throwing
*/
// Make a JSONException to signal a syntax error, with the current position
// appended.
public JSONException syntaxError(String message) {
return new JSONException(message + toString());
}
/**
* Make a printable string of this JSONTokener.
*
* @return " at {index} [character {character} line {line}]"
*/
// Returns " at {index} [character {character} line {line}]".
@Override
public String toString() {
@@ -16,11 +16,8 @@
*/
package me.eccentric_nz.gamemodeinventories;
/**
* Class to compare version strings. Borrowed from StackOverflow.
*
* @author alex http://stackoverflow.com/users/1445568/alex
*/
// Compares dotted version strings numerically.
// Borrowed from StackOverflow user alex (http://stackoverflow.com/users/1445568/alex).
public class Version implements Comparable<Version> {
private final String version;
@@ -12,13 +12,8 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
// The single authority on which gamemodes GameModeInventories-OG sanctions, and
// where. Every enforcement point inside this plugin asks it, and it is published
// so other plugins enforce the same rule instead of reimplementing it.
//
// Obtain it from the Bukkit services manager, or reflectively through
// GameModeInventories#getGameModePolicy() when compiling against this plugin is
// not practical.
// The single authority on which gamemodes GameModeInventories-OG sanctions and where; published so other
// plugins enforce the same rule. Obtain via the Bukkit services manager or GameModeInventories#getGameModePolicy().
public final class GameModePolicy {
public static final String ANYWHERE_PERMISSION = "gamemodeinventories.anywhere";
@@ -48,9 +43,8 @@ public final class GameModePolicy {
}
// Whether this plugin's rules permit the player to be in the gamemode at the
// location. Survival is always permitted; creative, spectator, and adventure
// follow the rules below.
// Whether this plugin's rules permit the player to hold the gamemode at the
// location. Survival is always permitted; the rest follow the rules below.
public boolean mayUse(Player player, GameMode gameMode, Location location) {
return switch (gameMode) {
@@ -64,9 +58,8 @@ public final class GameModePolicy {
}
// Nothing grants adventure as a privilege, but minigames put their players in
// it legitimately, so it is refused only in the worlds that are meant to stay
// survival. Minigame worlds must be left off that list.
// Minigames put players in adventure legitimately, so it is refused only in
// worlds meant to stay survival; minigame worlds must be left off that list.
public boolean mayUseAdventureAt(Location location) {
if (location == null || location.getWorld() == null)
@@ -78,9 +71,8 @@ public final class GameModePolicy {
}
// Creative is staff only. The permission says who, the region says where, and
// both are required: being inside a creative region is not a licence for an
// ordinary player who reached creative by some other route.
// Creative is staff only. The permission says who, the region says where,
// and both are required: a region alone licenses no ordinary player.
public boolean mayUseCreativeAt(Player player, Location location) {
if (player.hasPermission(ANYWHERE_PERMISSION))
@@ -111,9 +103,8 @@ public final class GameModePolicy {
}
// The sanctioned programmatic switch: validated against this policy first,
// then flagged internal so the region listener trusts it. False means
// refused here or cancelled by another plugin (read-back mismatch).
// The sanctioned programmatic switch: policy-validated, then flagged internal
// so the listener trusts it. False: refused here or cancelled elsewhere.
public boolean changeGameMode(Player player, GameMode gameMode) {
if (!mayUse(player, gameMode, player.getLocation()))
@@ -14,9 +14,6 @@ import me.eccentric_nz.gamemodeinventories.GMIDebug;
import me.eccentric_nz.gamemodeinventories.GameModeInventories;
import org.bukkit.scheduler.BukkitRunnable;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBlockLoader extends BukkitRunnable {
private final GameModeInventories plugin;
@@ -7,9 +7,6 @@ import java.sql.*;
import me.eccentric_nz.gamemodeinventories.GMIDebug;
import me.eccentric_nz.gamemodeinventories.GameModeInventories;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesBlocksConverter {
private final GameModeInventories plugin;
@@ -76,9 +73,8 @@ public class GameModeInventoriesBlocksConverter {
// Execute the batch
int[] updateCounts = ps.executeBatch();
// All statements were successfully executed.
// updateCounts contains one element for each batched statement.
// updateCounts[i] contains the number of rows affected by that statement.
// All statements executed: updateCounts holds one
// element (rows affected) per batched statement.
processUpdateCounts(updateCounts);
// Since there were no errors, commit
connection.commit();
@@ -96,10 +92,8 @@ public class GameModeInventoriesBlocksConverter {
// Not all of the statements were successfully executed
int[] updateCounts = ex.getUpdateCounts();
// Some databases will continue to execute after one fails.
// If so, updateCounts.length will equal the number of batched statements.
// If not, updateCounts.length will equal the number of successfully executed
// statements
// Some databases continue past a failure: updateCounts.length is then
// the batched count, otherwise the successfully executed count.
processUpdateCounts(updateCounts);
}
@@ -10,9 +10,6 @@ import java.sql.Statement;
import java.util.logging.Level;
import me.eccentric_nz.gamemodeinventories.GameModeInventories;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesMySQL {
private final GameModeInventories plugin;
@@ -7,9 +7,6 @@ import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import me.eccentric_nz.gamemodeinventories.GameModeInventories;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesMySQLConnectionPool {
private static boolean isMySQL = false;
@@ -3,9 +3,6 @@
*/
package me.eccentric_nz.gamemodeinventories.database;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesQueueData {
private final String worldchunk;
@@ -5,23 +5,14 @@ import me.eccentric_nz.gamemodeinventories.GameModeInventories;
public class GameModeInventoriesQueueDrain {
/**
*
*/
private final GameModeInventories plugin;
/**
* @param plugin
*/
public GameModeInventoriesQueueDrain(GameModeInventories plugin) {
this.plugin = plugin;
}
/**
*
*/
public void forceDrainQueue() {
plugin.debug("Forcing recorder queue to run a new batch before shutdown...", GMIDebug.INFO);
@@ -2,10 +2,8 @@ package me.eccentric_nz.gamemodeinventories.database;
public class GameModeInventoriesRecordingManager {
/**
* If the recorder skips running we need to count because if this happens x
* times in a row, the recorder will delay itself so we don't kill the server
*/
// Counts skipped recorder runs: after x skips in a row the recorder delays
// itself so it does not kill the server.
public static int failedDbConnectionCount = 0;
}
@@ -6,18 +6,12 @@ public class GameModeInventoriesRecordingQueue {
private static final LinkedBlockingQueue<GameModeInventoriesQueueData> QUEUE = new LinkedBlockingQueue<GameModeInventoriesQueueData>();
/**
* @return the size of the QUEUE
*/
public static int getQueueSize() {
return QUEUE.size();
}
/**
* @param data
*/
public static void addToQueue(final GameModeInventoriesQueueData data) {
if (data == null) {
@@ -30,9 +24,6 @@ public class GameModeInventoriesRecordingQueue {
}
/**
* @return the QUEUE
*/
public static LinkedBlockingQueue<GameModeInventoriesQueueData> getQUEUE() {
return QUEUE;
@@ -10,9 +10,6 @@ import java.sql.Statement;
import java.util.logging.Level;
import me.eccentric_nz.gamemodeinventories.GameModeInventories;
/**
* @author eccentric_nz
*/
public class GameModeInventoriesSQLite {
private final GameModeInventories plugin;