Release 1.18.0 (#1876)

## Change Log 

* Island range perms could be 2x island distance

This could allow protection ranges to be much greater than the island
range and therefore overflow into adjacent islands.

https://github.com/BentoBoxWorld/BentoBox/issues/1851

* Ensure maxEverProtectionRange is less than range.

https://github.com/BentoBoxWorld/BentoBox/issues/1851

* Added test class for Island.

* Added access to private fields for JUnit tests

* Added Sonar Properties to POM

* Changes to analyze using sonar.

* Remove zip reference

* Avoid zipSlip vulnerability.

* Removed the unused WorldEdit hook. (#1853)

If someone wants to add it back later they can, but this code does
nothing right now.

* Requires nonNull parameters for User.instanceOf (#1852)

* Requires nonNull parameters for User.instanceOf

The only reason why User.instanceOf was returning a potential null was
if the parameter was null. Further absolutely no null checking was being
done, so the assumption was that User.instanceOf should never return a
null. This corrects the annotations and requires non-Null parameters.

* Remove null player test

* Fix JavaDoc for GameModeAddon inWorld method

* Fix max-range bug

* Remove illegal tag as it's not needed

* Code smell reduction

* Add missing packages so tests can pass.

* Non null user methods (#1856)

* This makes some User methods non-null.

Instead of returning null, some methods will throw an error if they are
called on non-Players. This means code does not have to do null checks.

* Perform null check in method.

* Null check

* Fix test

* Fix test.

* Npe squashing (#1857)

* Fix hanging [uuid] in info.

* NPE checking

* Make getProtectionCenter nonNull

* More NPE fixes.

* Fix test

* Make getPlayer() and getOfflinePlayer() nonNull returns

This requires addons to not use null checks and instead us the isPlayer
or isOfflinePlayer methods.

* NPE blockers

* Deprecate CompositeCommand isPlayer method.

* Fix test

* Use isPlayer instead of null check.

Refactor code to be easier to understand.

* Fix

* Fix some code smells.

* Prevent NPE possibility.

* Fix "ugly" enchant name. (#1858)

Enchant names did not have a touch of Util#prettifyText code.

* Remove deprecated events.

* Fix IslandSethomeCommand test

* Fix tests - just counts of events.

* Added API to get a translation without color conversion

It may be necessary to read the translation without converting colors to
Bukkit colors.

* Fix tests.

* Fix test.

* Version NPE protections.

* 1.18.0 (#1860)

* Mark all home-related methods in PlayersManager as deprecated.

* Fix bug where maxHomes was shown as null

* Version 1.18.0

API changes may break compatibility with Addons.

* Remove usage of deprecated methods except for migration code.

* Prevent NPE. Check isPlayer instead of getWorld() == null

* Fix nullability issue and added to @Deprecated annotations

* Added deprecation notices to home methods in Players

* Fix missing color conversion for translations.

* Fix mis-statement of island protection coordinates in info command.

* Fix tests

* Fix missing edge deletion of island.

The bounding box was erroneously being made smaller when it was not
required because the inBounds check does that already.

https://github.com/BentoBoxWorld/BentoBox/issues/1863

* Prevent rare NPE

* Ensure oldIsland is never null.

* Refactored setowner command and added test class

* API: Require getWorldSettings to be a game mode world

* Fix tests and refactor code

* Fix test

IWM inWworld needs to return true

* Fix test

IWM inWorld must return true

* Put default getHandlers back in for backwards compatibility

Without them, too many older addons break. They need updating to have
their own handlers. Once that is done, the default ones can be removed
maybe.

* Refactor code for clarity.

* NPE protections

* Prevent NPE

@Poslovich - you were right!

* Throw an error if player is null

* Prevent NPE

* Prevent NPE

* Do a null check

* World should never be null.

* Require non-null world

* Require owner to be non-null. It should never be null

* Prevent NPEs

* Clear the going home flag for edge cases

There were a few potential times when the flag may not have been
cleared. These were mostly teleport failure scenarios. Hopefully, this
is all of them.

https://github.com/BentoBoxWorld/BentoBox/issues/1864

* Shift priority of EntityPortalEnterEvent to HIGH

https://github.com/BentoBoxWorld/BentoBox/issues/1866

This will allow other plugins running at NORMAL to cancel the event
before BentoBox does something.

* Increase priority of EntityPortalEvent listener

https://github.com/BentoBoxWorld/BentoBox/issues/1866

* Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1868

* Code refactoring around User.getInstance(player)

Co-authored-by: BONNe <bonne@bonne.id.lv>
Co-authored-by: Fredthedoggy <45927799+Fredthedoggy@users.noreply.github.com>
Co-authored-by: Justin <jstnf@users.noreply.github.com>
Co-authored-by: gecko10000 <60494179+levtey@users.noreply.github.com>
This commit is contained in:
tastybento 2021-11-08 21:28:12 -08:00 committed by GitHub
parent a6d70d6e90
commit df2b445002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
168 changed files with 2503 additions and 1633 deletions

View File

@ -24,15 +24,18 @@ jobs:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache local Maven repository
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build
run: mvn --batch-mode clean org.jacoco:jacoco-maven-plugin:prepare-agent install
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BentoBoxWorld_BentoBox
- run: mvn --batch-mode clean org.jacoco:jacoco-maven-plugin:prepare-agent install
- run: mkdir staging && cp target/*.jar staging
- name: Save artifacts
uses: actions/upload-artifact@v2

36
pom.xml
View File

@ -83,7 +83,9 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.17.3</build.version>
<build.version>1.18.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
<!-- Profiles will allow to automatically change build version. -->
@ -339,7 +341,33 @@
<version>3.0.0-M5</version>
<configuration>
<argLine>
--illegal-access=permit
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens
java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens
java.base/java.util.regex=ALL-UNNAMED
--add-opens
java.base/java.nio.channels.spi=ALL-UNNAMED
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens
java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/sun.nio.fs=ALL-UNNAMED
--add-opens java.base/sun.nio.cs=ALL-UNNAMED
--add-opens java.base/java.nio.file=ALL-UNNAMED
--add-opens
java.base/java.nio.charset=ALL-UNNAMED
--add-opens
java.base/java.lang.reflect=ALL-UNNAMED
--add-opens
java.logging/java.util.logging=ALL-UNNAMED
--add-opens java.base/java.lang.ref=ALL-UNNAMED
--add-opens java.base/java.util.jar=ALL-UNNAMED
--add-opens java.base/java.util.zip=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
@ -358,12 +386,12 @@
<failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption>
<!-- To compile with Java 11, this tag may be required -->
<!-- <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable> -->
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>install</phase>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>

View File

@ -2,7 +2,6 @@ package world.bentobox.bentobox;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
@ -23,7 +22,6 @@ import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.hooks.DynmapHook;
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.hooks.WorldEditHook;
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
import world.bentobox.bentobox.listeners.BannedCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon;
@ -103,7 +101,7 @@ public class BentoBox extends JavaPlugin {
logWarning("BentoBox is tested only on the following Spigot versions:");
List<String> versions = ServerCompatibility.ServerVersion.getVersions(ServerCompatibility.Compatibility.COMPATIBLE, ServerCompatibility.Compatibility.SUPPORTED)
.stream().map(ServerCompatibility.ServerVersion::toString).collect(Collectors.toList());
.stream().map(ServerCompatibility.ServerVersion::toString).toList();
logWarning(String.join(", ", versions));
logWarning("**************************************");
@ -172,6 +170,7 @@ public class BentoBox extends JavaPlugin {
completeSetup(loadTime);
} catch (Exception e) {
fireCriticalError(e.getMessage(), "");
e.printStackTrace();
}
});
}
@ -227,7 +226,6 @@ public class BentoBox extends JavaPlugin {
// Register additional hooks
hooksManager.registerHook(new DynmapHook());
hooksManager.registerHook(new WorldEditHook());
// TODO: re-enable after rework
//hooksManager.registerHook(new LangUtilsHook());
@ -333,7 +331,7 @@ public class BentoBox extends JavaPlugin {
* @since 1.16.0
*/
public PlayersManager getPlayersManager() {
return playersManager;
return getPlayers();
}
/**
@ -352,7 +350,7 @@ public class BentoBox extends JavaPlugin {
* @since 1.16.0
*/
public IslandsManager getIslandsManager() {
return islandsManager;
return getIslands();
}
private static void setInstance(BentoBox plugin) {

View File

@ -79,8 +79,8 @@ public class AddonClassLoader extends URLClassLoader {
*/
@NonNull
public static AddonDescription asDescription(YamlConfiguration data) throws InvalidAddonDescriptionException {
AddonDescription.Builder builder = new AddonDescription.Builder(data.getString("main"), data.getString("name"), data.getString("version"))
.authors(data.getString("authors"))
AddonDescription.Builder builder = new AddonDescription.Builder(Objects.requireNonNull(data.getString("main")), Objects.requireNonNull(data.getString("name")), Objects.requireNonNull(data.getString("version")))
.authors(Objects.requireNonNull(data.getString("authors")))
.metrics(data.getBoolean("metrics", true))
.repository(data.getString("repository", ""));
@ -92,7 +92,7 @@ public class AddonClassLoader extends URLClassLoader {
if (softDepend != null) {
builder.softDependencies(Arrays.asList(softDepend.split("\\s*,\\s*")));
}
builder.icon(Material.getMaterial(data.getString("icon", "PAPER")));
builder.icon(Objects.requireNonNull(Material.getMaterial(data.getString("icon", "PAPER"))));
String apiVersion = data.getString("api-version");
if (apiVersion != null) {

View File

@ -158,26 +158,35 @@ public final class AddonDescription {
* @return the permissions
* @since 1.13.0
*/
@Nullable
public ConfigurationSection getPermissions() {
return permissions;
}
public static class Builder {
private @NonNull
final String main;
private @NonNull
final String name;
private @NonNull
final String version;
private @NonNull String description = "";
private @NonNull List<String> authors = new ArrayList<>();
private @NonNull List<String> dependencies = new ArrayList<>();
private @NonNull List<String> softDependencies = new ArrayList<>();
@NonNull
private final String main;
@NonNull
private final String name;
@NonNull
private final String version;
@NonNull
private String description = "";
@NonNull
private List<String> authors = new ArrayList<>();
@NonNull
private List<String> dependencies = new ArrayList<>();
@NonNull
private List<String> softDependencies = new ArrayList<>();
private boolean metrics = true;
private @NonNull String repository = "";
private @NonNull Material icon = Material.PAPER;
private @NonNull String apiVersion = "1";
private @Nullable ConfigurationSection permissions;
@NonNull
private String repository = "";
@NonNull
private Material icon = Material.PAPER;
@NonNull
private String apiVersion = "1";
@Nullable
private ConfigurationSection permissions;
/**
* @since 1.1
@ -279,6 +288,6 @@ public final class AddonDescription {
@Override
public String toString() {
return "AddonDescription [" + (name != null ? "name=" + name + ", " : "")
+ (version != null ? "version=" + version : "") + "]";
+ "version=" + version + "]";
}
}

View File

@ -52,9 +52,9 @@ public abstract class GameModeAddon extends Addon {
public abstract WorldSettings getWorldSettings();
/**
* Checks if a player is in any of the island worlds
* @param loc - player to check
* @return true if in a world or false if not
* Checks if location is governed by this game mode
* @param loc - location to check
* @return true if location in covered by this addon or false if not
*/
public boolean inWorld(Location loc) {
return Util.sameWorld(loc.getWorld(), islandWorld);
@ -63,7 +63,7 @@ public abstract class GameModeAddon extends Addon {
/**
* Checks if world is governed by this game mode
* @param world - world to check
* @return true if in a world or false if not
* @return true if world in covered by this addon or false if not
* @since 1.2.0
*/
public boolean inWorld(World world) {

View File

@ -218,7 +218,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* subcommands until it finds the right object and then runs execute on it.
*/
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
public boolean execute(@NonNull CommandSender sender, @NonNull String label, String[] args) {
// Get the User instance for this sender
User user = User.getInstance(sender);
// Fire an event to see if this command should be cancelled
@ -352,7 +352,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
}
@Override
public BentoBox getPlugin() {
public @NonNull BentoBox getPlugin() {
return plugin;
}
@ -422,7 +422,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
}
@Override
public String getUsage() {
public @NonNull String getUsage() {
return "/" + usage;
}
@ -476,9 +476,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* Convenience method to check if a user is a player
* @param user - the User
* @return true if sender is a player
* @deprecated use {@link User#isPlayer()}
* @forRemove 1.18.0
*/
@Deprecated
protected boolean isPlayer(User user) {
return user.getPlayer() != null;
return user.isPlayer();
}
/**
@ -521,7 +524,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @return The instance of this {@link Command}.
*/
@Override
public Command setDescription(String description) {
public @NonNull Command setDescription(@NonNull String description) {
super.setDescription(description);
return this;
}
@ -575,7 +578,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* This creates the full linking chain of commands
*/
@Override
public Command setUsage(String usage) {
public @NonNull Command setUsage(@NonNull String usage) {
// Go up the chain
CompositeCommand parentCommand = getParent();
StringBuilder u = new StringBuilder().append(getLabel()).append(" ").append(usage);
@ -590,7 +593,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
@Override
@NonNull
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) {
public List<String> tabComplete(final @NonNull CommandSender sender, final @NonNull String alias, final String[] args) {
List<String> options = new ArrayList<>();
// Get command object based on args entered so far
CompositeCommand command = getCommandFromArgs(args);

View File

@ -41,12 +41,14 @@ public class AdminDeleteCommand extends ConfirmableCommand {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
UUID owner = getIslands().getOwner(getWorld(), targetUUID);
if (owner == null) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Team members should be kicked before deleting otherwise the whole team will become weird
if (getIslands().inTeam(getWorld(), targetUUID) && getIslands().getOwner(getWorld(), targetUUID).equals(targetUUID)) {
if (getIslands().inTeam(getWorld(), targetUUID) && owner.equals(targetUUID)) {
user.sendMessage("commands.admin.delete.cannot-delete-owner");
return false;
}
@ -55,11 +57,6 @@ public class AdminDeleteCommand extends ConfirmableCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
// If args are not right, show help
if (args.size() != 1) {
showHelp(this, user);
return false;
}
// Get target
UUID targetUUID = getPlayers().getUUID(args.get(0));
// Confirm
@ -85,38 +82,12 @@ public class AdminDeleteCommand extends ConfirmableCommand {
User target = User.getInstance(targetUUID);
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(getWorld(), targetUUID);
if (target.isOnline()) {
// Execute commands when leaving
Util.runCommands(user, getIWM().getOnLeaveCommands(getWorld()), "leave");
// Remove money inventory etc.
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
target.getPlayer().getEnderChest().clear();
}
if (getIWM().isOnLeaveResetInventory(getWorld())) {
target.getPlayer().getInventory().clear();
}
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
Util.resetHealth(target.getPlayer());
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
target.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
target.getPlayer().setTotalExperience(0);
}
if (target.isPlayer() && target.isOnline()) {
cleanUp(user, target);
}
vector = oldIsland.getCenter().toVector();
getIslands().deleteIsland(oldIsland, true, targetUUID);
}
getPlayers().clearHomeLocations(getWorld(), targetUUID);
if (vector == null) {
user.sendMessage("general.success");
} else {
@ -124,6 +95,36 @@ public class AdminDeleteCommand extends ConfirmableCommand {
}
}
private void cleanUp(User user, User target) {
// Execute commands when leaving
Util.runCommands(user, getIWM().getOnLeaveCommands(getWorld()), "leave");
// Remove money inventory etc.
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
target.getPlayer().getEnderChest().clear();
}
if (getIWM().isOnLeaveResetInventory(getWorld())) {
target.getPlayer().getInventory().clear();
}
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
Util.resetHealth(target.getPlayer());
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
target.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
target.getPlayer().setTotalExperience(0);
}
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";

View File

@ -101,6 +101,10 @@ public class AdminSetrankCommand extends CompositeCommand {
} else {
island = getIslands().getIsland(getWorld(), targetUUID);
}
if (island == null) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
int currentRank = island.getRank(target);
island.setRank(target, rankValue);
IslandEvent.builder()

View File

@ -65,10 +65,8 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
.build();
}
// If island is owned, then unregister the owner and any members
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
getIslands().removePlayer(getWorld(), m);
getPlayers().clearHomeLocations(getWorld(), m);
});
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m ->
getIslands().removePlayer(getWorld(), m));
}
getIslands().setSpawn(i);
i.setSpawnPoint(World.Environment.NORMAL, user.getLocation());

View File

@ -44,15 +44,15 @@ public class AdminSwitchCommand extends ConfirmableCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
boolean switchState = user.getMetaData("AdminCommandSwitch").map(MetaDataValue::asBoolean).orElse(false);
boolean switchState = user.getMetaData(META_TAG).map(MetaDataValue::asBoolean).orElse(false);
if (switchState) {
// Turn off
user.putMetaData("AdminCommandSwitch", new MetaDataValue(false));
user.putMetaData(META_TAG, new MetaDataValue(false));
user.sendMessage("commands.admin.switch.adding"); // Adding protection bypass
user.sendMessage("general.success");
} else {
// Turn on
user.putMetaData("AdminCommandSwitch", new MetaDataValue(true));
user.putMetaData(META_TAG, new MetaDataValue(true));
user.sendMessage("commands.admin.switch.removing"); // Removing protection bypass
user.sendMessage("general.success");
}

View File

@ -19,6 +19,7 @@ import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
public class AdminTeleportCommand extends CompositeCommand {
private static final String NOT_SAFE = "general.errors.no-safe-location-found";
private @Nullable UUID targetUUID;
private @Nullable User userToTeleport;
@ -86,9 +87,13 @@ public class AdminTeleportCommand extends CompositeCommand {
} else if (getLabel().equals("tpend")) {
world = getPlugin().getIWM().getEndWorld(getWorld());
}
if (world == null) {
user.sendMessage(NOT_SAFE);
return false;
}
Location warpSpot = getSpot(world);
if (world == null || warpSpot == null) {
user.sendMessage("general.errors.no-safe-location-found");
if (warpSpot == null) {
user.sendMessage(NOT_SAFE);
return false;
}
@ -99,7 +104,7 @@ public class AdminTeleportCommand extends CompositeCommand {
Player player = user.getPlayer();
if (args.size() == 2) {
player = userToTeleport.getPlayer();
failureMessage = userToTeleport.getTranslation("general.errors.no-safe-location-found");
failureMessage = userToTeleport.getTranslation(NOT_SAFE);
}
// Teleport
@ -118,7 +123,7 @@ public class AdminTeleportCommand extends CompositeCommand {
return island.getSpawnPoint(world.getEnvironment());
}
// Return the default island protection center
return getIslands().getIslandLocation(getWorld(), targetUUID).toVector().toLocation(world);
return island.getProtectionCenter().toVector().toLocation(world);
}
@Override

View File

@ -75,10 +75,7 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
.rankChange(RanksManager.OWNER_RANK, RanksManager.VISITOR_RANK)
.build();
// Remove all island members
oldIsland.getMemberSet().forEach(m -> {
getIslands().removePlayer(getWorld(), m);
getPlayers().clearHomeLocations(getWorld(), m);
});
oldIsland.getMemberSet().forEach(m -> getIslands().removePlayer(getWorld(), m));
// Remove all island players that reference this island
oldIsland.getMembers().clear();
getIslands().save(oldIsland);

View File

@ -64,21 +64,22 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
protected void showClipboard(User user) {
displayClipboards.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
if (!user.getPlayer().isOnline()) {
if (!user.isPlayer() || !user.getPlayer().isOnline()) {
hideClipboard(user);
}
if (clipboards.containsKey(user.getUniqueId())) {
BlueprintClipboard clipboard = clipboards.get(user.getUniqueId());
if (clipboard.getPos1() != null && clipboard.getPos2() != null) {
paintAxis(user, clipboard);
}
paintAxis(user, clipboard);
}
}, 20, 20));
}
private void paintAxis(User user, BlueprintClipboard clipboard) {
if (clipboard.getPos1() == null || clipboard.getPos2() == null) {
return;
}
int minX = Math.min(clipboard.getPos1().getBlockX(), clipboard.getPos2().getBlockX());
int minY = Math.min(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
int minZ = Math.min(clipboard.getPos1().getBlockZ(), clipboard.getPos2().getBlockZ());

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.admin.blueprints;
import java.util.List;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -34,7 +35,7 @@ public class AdminBlueprintOriginCommand extends CompositeCommand {
}
// Get the block player is looking at
Block b = user.getPlayer().getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
Block b = Objects.requireNonNull(user.getPlayer()).getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
if (b != null) {
clipboard.setOrigin(b.getLocation().toVector());
user.getPlayer().sendBlockChange(b.getLocation(), Material.REDSTONE_BLOCK.createBlockData());

View File

@ -30,7 +30,7 @@ public class AdminBlueprintPos1Command extends CompositeCommand {
return false;
}
clipboard.setPos1(user.getLocation());
user.sendMessage("commands.admin.blueprint.set-pos1", "[vector]", Util.xyz(clipboard.getPos1().toVector()));
user.sendMessage("commands.admin.blueprint.set-pos1", "[vector]", Util.xyz(user.getLocation().toVector()));
parent.getClipboards().put(user.getUniqueId(), clipboard);
parent.showClipboard(user);
return true;

View File

@ -30,7 +30,7 @@ public class AdminBlueprintPos2Command extends CompositeCommand {
return false;
}
clipboard.setPos2(user.getLocation());
user.sendMessage("commands.admin.blueprint.set-pos2", "[vector]", Util.xyz((clipboard.getPos2()).toVector()));
user.sendMessage("commands.admin.blueprint.set-pos2", "[vector]", Util.xyz(user.getLocation().toVector()));
parent.getClipboards().put(user.getUniqueId(), clipboard);
parent.showClipboard(user);
return true;

View File

@ -55,7 +55,7 @@ public class AdminBlueprintSaveCommand extends ConfirmableCommand {
private boolean hideAndSave(User user, AdminBlueprintCommand parent, BlueprintClipboard clipboard, String name) {
parent.hideClipboard(user);
boolean result = new BlueprintClipboardManager(getPlugin(), parent.getBlueprintsFolder(), clipboard).save(user, name);
if (result) {
if (result && clipboard.getBlueprint() != null) {
getPlugin().getBlueprintsManager().addBlueprint(getAddon(), clipboard.getBlueprint());
}
return result;

View File

@ -22,7 +22,7 @@ public class NamePrompt extends StringPrompt {
private final String oldName;
private final BentoBox plugin;
public NamePrompt(BentoBox plugin, @NonNull Island island, User user, String oldName) {
public NamePrompt(BentoBox plugin, @NonNull Island island, @NonNull User user, String oldName) {
this.plugin = plugin;
this.island = island;
this.user = user;
@ -30,12 +30,12 @@ public class NamePrompt extends StringPrompt {
}
@Override
public String getPromptText(ConversationContext context) {
public @NonNull String getPromptText(@NonNull ConversationContext context) {
return user.getTranslation("commands.island.renamehome.enter-new-name");
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
if (island.renameHome(oldName, input)) {
plugin.getIslands().save(island);
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("general.success"));

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.admin.range;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.eclipse.jdt.annotation.NonNull;
@ -52,7 +53,7 @@ public class AdminRangeAddCommand extends CompositeCommand {
return false;
}
Island island = getIslands().getIsland(getWorld(), targetUUID);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
int newRange = island.getProtectionRange() + Integer.parseInt(args.get(1));
if (newRange > island.getRange() * 2) {

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.admin.range;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.eclipse.jdt.annotation.NonNull;
@ -52,7 +53,7 @@ public class AdminRangeRemoveCommand extends CompositeCommand {
return false;
}
Island island = getIslands().getIsland(getWorld(), targetUUID);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
int newRange = island.getProtectionRange() - Integer.parseInt(args.get(1));
if (newRange <= 1) {

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.admin.range;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
@ -45,7 +46,7 @@ public class AdminRangeResetCommand extends CompositeCommand {
}
// Get island
Island island = getIslands().getIsland(getWorld(), targetUUID);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
// Get old range for event
int oldRange = island.getProtectionRange();

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.admin.range;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
@ -52,7 +53,7 @@ public class AdminRangeSetCommand extends CompositeCommand {
int range = Integer.parseInt(args.get(1));
// Get island
Island island = getIslands().getIsland(getWorld(), targetUUID);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
// Do some sanity checks to make sure the new protection range won't cause problems
if (range < 1) {

View File

@ -72,7 +72,6 @@ public class AdminTeamKickCommand extends CompositeCommand {
target.sendMessage("commands.admin.team.kick.admin-kicked");
getIslands().removePlayer(getWorld(), targetUUID);
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
// Fire event so add-ons know

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
@ -54,11 +55,10 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
}
// Get the User corresponding to the current owner
User previousOwner = User.getInstance(previousOwnerUUID);
User target = User.getInstance(targetUUID);
// Fire event so add-ons know
Island island = getIslands().getIsland(getWorld(), targetUUID);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID));
// Call the setowner event
TeamEvent.builder()
.island(island)
@ -82,15 +82,16 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
// Call the rank change event for the old island owner
// We need to call it AFTER the actual change.
IslandEvent.builder()
.island(island)
.involvedPlayer(previousOwnerUUID)
.admin(true)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwner))
.build();
if (previousOwnerUUID != null) {
// We need to call it AFTER the actual change.
IslandEvent.builder()
.island(island)
.involvedPlayer(previousOwnerUUID)
.admin(true)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwnerUUID))
.build();
}
return true;
}
}

View File

@ -51,8 +51,8 @@ public class IslandBanCommand extends CompositeCommand {
return false;
}
// Check rank to use command
Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user);
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), user));
int rank = island.getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
return false;
@ -72,7 +72,7 @@ public class IslandBanCommand extends CompositeCommand {
user.sendMessage("commands.island.ban.cannot-ban-member");
return false;
}
if (getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) {
if (island.isBanned(targetUUID)) {
user.sendMessage("commands.island.ban.player-already-banned");
return false;
}
@ -95,7 +95,7 @@ public class IslandBanCommand extends CompositeCommand {
}
private boolean ban(@NonNull User issuer, User target) {
Island island = getIslands().getIsland(getWorld(), issuer.getUniqueId());
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), issuer.getUniqueId()));
// Check if player can ban any more players
int banLimit = issuer.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));

View File

@ -113,31 +113,19 @@ public class IslandResetCommand extends ConfirmableCommand {
}
}
/**
* Reset island
* @param user user
* @param name name of Blueprint Bundle
* @return true if successful
*/
private boolean resetIsland(User user, String name) {
// Get the player's old island
Island oldIsland = getIslands().getIsland(getWorld(), user);
// Fire island preclear event
IslandEvent.builder()
.involvedPlayer(user.getUniqueId())
.reason(Reason.PRECLEAR)
.island(oldIsland)
.oldIsland(oldIsland)
.location(oldIsland.getCenter())
.build();
// Reset the island
if (oldIsland != null) {
deleteOldIsland(user, oldIsland);
}
user.sendMessage("commands.island.create.creating-island");
// Kick all island members (including the owner)
kickMembers(oldIsland);
// Add a reset
getPlayers().addReset(getWorld(), user.getUniqueId());
// Reset the homes of the player
getPlayers().clearHomeLocations(getWorld(), user.getUniqueId());
// Create new island and then delete the old one
try {
Builder builder = NewIsland.builder()
@ -157,6 +145,25 @@ public class IslandResetCommand extends ConfirmableCommand {
return true;
}
private void deleteOldIsland(User user, Island oldIsland) {
// Fire island preclear event
IslandEvent.builder()
.involvedPlayer(user.getUniqueId())
.reason(Reason.PRECLEAR)
.island(oldIsland)
.oldIsland(oldIsland)
.location(oldIsland.getCenter())
.build();
// Reset the island
// Kick all island members (including the owner)
kickMembers(oldIsland);
// Add a reset
getPlayers().addReset(getWorld(), user.getUniqueId());
}
/**
* Kicks the members (incl. owner) of the island.
* @since 1.7.0

View File

@ -6,6 +6,7 @@ import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
@ -40,7 +41,7 @@ public class IslandSethomeCommand extends ConfirmableCommand {
// Check number of homes
int maxHomes = getIslands().getMaxHomes(island);
if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) {
user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(island.getMaxHomes()));
user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
user.sendMessage("commands.island.sethome.homes-are");
island.getHomes().keySet().stream().filter(s -> !s.isEmpty()).forEach(s -> user.sendMessage("commands.island.sethome.home-list-syntax", TextVariables.NAME, s));
return false;
@ -51,29 +52,30 @@ public class IslandSethomeCommand extends ConfirmableCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
String number = String.join(" ", args);
WorldSettings ws = getIWM().getWorldSettings(user.getWorld());
// Check if the player is in the Nether
if (getIWM().isNether(user.getWorld())) {
// Check if he is (not) allowed to set his home here
if (!getIWM().getWorldSettings(user.getWorld()).isAllowSetHomeInNether()) {
if (!ws.isAllowSetHomeInNether()) {
user.sendMessage("commands.island.sethome.nether.not-allowed");
return false;
}
// Check if a confirmation is required
if (getIWM().getWorldSettings(user.getWorld()).isRequireConfirmationToSetHomeInNether()) {
if (ws.isRequireConfirmationToSetHomeInNether()) {
askConfirmation(user, user.getTranslation("commands.island.sethome.nether.confirmation"), () -> doSetHome(user, number));
} else {
doSetHome(user, number);
}
} else if (getIWM().isEnd(user.getWorld())) { // Check if the player is in the End
// Check if he is (not) allowed to set his home here
if (!getIWM().getWorldSettings(user.getWorld()).isAllowSetHomeInTheEnd()) {
if (!ws.isAllowSetHomeInTheEnd()) {
user.sendMessage("commands.island.sethome.the-end.not-allowed");
return false;
}
// Check if a confirmation is required
if (getIWM().getWorldSettings(user.getWorld()).isRequireConfirmationToSetHomeInTheEnd()) {
if (ws.isRequireConfirmationToSetHomeInTheEnd()) {
askConfirmation(user, user.getTranslation("commands.island.sethome.the-end.confirmation"), () -> doSetHome(user, number));
} else {
doSetHome(user, number);

View File

@ -6,6 +6,8 @@ import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -21,6 +23,8 @@ import world.bentobox.bentobox.util.Util;
*/
public class IslandUnbanCommand extends CompositeCommand {
private @Nullable UUID targetUUID;
public IslandUnbanCommand(CompositeCommand islandCommand) {
super(islandCommand, "unban", "pardon");
}
@ -55,7 +59,7 @@ public class IslandUnbanCommand extends CompositeCommand {
return false;
}
// Get target player
UUID targetUUID = getPlayers().getUUID(args.get(0));
targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
@ -65,7 +69,7 @@ public class IslandUnbanCommand extends CompositeCommand {
user.sendMessage("commands.island.unban.cannot-unban-yourself");
return false;
}
if (!getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) {
if (!island.isBanned(targetUUID)) {
user.sendMessage("commands.island.unban.player-not-banned");
return false;
}
@ -75,7 +79,7 @@ public class IslandUnbanCommand extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
User target = User.getInstance(getPlayers().getUUID(args.get(0)));
User target = User.getInstance(targetUUID);
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
// Run the event

View File

@ -148,6 +148,10 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
Island island = getIslands().getIsland(getWorld(), playerUUID);
// Get the team's island
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
if (teamIsland == null) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
return;
}
if (teamIsland.getMemberSet(RanksManager.MEMBER_RANK, true).size() > getIslands().getMaxMembers(teamIsland, RanksManager.MEMBER_RANK)) {
user.sendMessage("commands.island.team.invite.errors.island-is-full");
return;
@ -158,8 +162,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
cleanPlayer(user);
// Add the player as a team member of the new island
getIslands().setJoinTeam(teamIsland, playerUUID);
//Move player to team's island
getPlayers().clearHomeLocations(getWorld(), playerUUID);
// Move player to team's island
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
// Delete the old island
if (island != null) {

View File

@ -83,7 +83,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
private void kick(User user, UUID targetUUID) {
User target = User.getInstance(targetUUID);
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID)); // Should never be null because of checks above
// Fire event
IslandBaseEvent event = TeamEvent.builder()
.island(oldIsland)

View File

@ -66,7 +66,7 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
user.sendMessage("commands.island.team.demote.errors.cant-demote-yourself");
return true;
}
if (!inTeam(getWorld(), target) || !getOwner(getWorld(), user).equals(getOwner(getWorld(), target))) {
if (!inTeam(getWorld(), target) || !Objects.requireNonNull(getOwner(getWorld(), user), "Island has no owner!").equals(getOwner(getWorld(), target))) {
user.sendMessage("general.errors.not-in-team");
return true;
}

View File

@ -1,12 +1,9 @@
package world.bentobox.bentobox.api.commands.island.team;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -35,9 +32,13 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
public boolean execute(User user, String label, List<String> args) {
UUID playerUUID = user.getUniqueId();
// Can use if in a team
boolean inTeam = getPlugin().getIslands().inTeam(getWorld(), playerUUID);
boolean inTeam = getIslands().inTeam(getWorld(), playerUUID);
if (!inTeam) {
user.sendMessage("general.errors.no-team");
return false;
}
UUID ownerUUID = getOwner(getWorld(), user);
if (!(inTeam && ownerUUID.equals(playerUUID))) {
if (ownerUUID == null || !ownerUUID.equals(playerUUID)) {
user.sendMessage("general.errors.not-owner");
return false;
}
@ -51,27 +52,23 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (!getIslands().inTeam(getWorld(), playerUUID)) {
user.sendMessage("general.errors.no-team");
return false;
}
if (targetUUID.equals(playerUUID)) {
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
return false;
}
if (!getPlugin().getIslands().getMembers(getWorld(), playerUUID).contains(targetUUID)) {
if (!getIslands().getMembers(getWorld(), playerUUID).contains(targetUUID)) {
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
return false;
}
// Fire event so add-ons can run commands, etc.
Island island = getIslands().getIsland(getWorld(), playerUUID);
Island island = getIslands().getIsland(getWorld(), user);
// Fire event so add-ons can run commands, etc.
IslandBaseEvent e = TeamEvent.builder()
.island(getIslands().getIsland(getWorld(), user.getUniqueId()))
.island(island)
.reason(TeamEvent.Reason.SETOWNER)
.involvedPlayer(targetUUID)
.build();
if (e.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(e.isCancelled())) {
if (e.isCancelled()) {
return false;
}
getIslands().setOwner(getWorld(), user, targetUUID);
@ -97,12 +94,8 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
List<String> options = new ArrayList<>();
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
for (UUID member : getPlugin().getIslands().getMembers(getWorld(), user.getUniqueId())) {
options.add(Bukkit.getServer().getOfflinePlayer(member).getName());
}
return Optional.of(Util.tabLimit(options, lastArg));
return Optional.of(Util.tabLimit(getIslands().getMembers(getWorld(), user.getUniqueId()).stream().map(getPlayers()::getName).toList(), lastArg));
}
}

View File

@ -11,6 +11,7 @@ import java.util.Objects;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
@ -22,14 +23,24 @@ import world.bentobox.bentobox.BentoBox;
*/
public abstract class BentoBoxEvent extends Event {
/**
* Event handler list
* @deprecated This field will be removed from BentoBoxEvent.
* Events must provide their own handlers.
*/
@Deprecated
private static final HandlerList handlers = new HandlerList();
/**
* This is here just for backwards compatibility. Users of BentoBoxEvent should implement their own getHandlers
*/
@Override
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
/**
* This is here just for backwards compatibility. Users of BentoBoxEvent should implement their own getHandlers
* @return HandlerList
*/
public static HandlerList getHandlerList() {
return handlers;
}
/**
* The default constructor is defined for cleaner code.
* This constructor assumes the BentoBoxEvent is synchronous.
@ -47,29 +58,6 @@ public abstract class BentoBoxEvent extends Event {
super(async);
}
/**
* @return HandlerList
* @deprecated this method will no longer be in future versions of the BentoBoxEvent.
* Each event must declare its own static handler and handler methods.
* Will be removed by https://github.com/BentoBoxWorld/BentoBox/pull/1615
*/
@Override
@Deprecated
public HandlerList getHandlers() {
return getHandlerList();
}
/**
* @return HandlerList
* @deprecated this method will no longer be in future versions of the BentoBoxEvent.
* Each event must declare its own static handler and handler methods.
* Will be removed by https://github.com/BentoBoxWorld/BentoBox/pull/1615
*/
@Deprecated
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get a map of key value pairs derived from the fields of this class by reflection.
* @return map

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.events;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
/**
* Fired when plugin is ready to play and all files are loaded
@ -12,7 +13,7 @@ public class BentoBoxReadyEvent extends BentoBoxEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.api.events;
import java.util.UUID;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
/**
* Fired when a message is going to an offline player
@ -16,7 +17,7 @@ public class OfflineMessageEvent extends BentoBoxEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.Map;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
/**
@ -16,7 +17,7 @@ public class AddonDisableEvent extends AddonBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.Map;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
/**
@ -16,7 +17,7 @@ public class AddonEnableEvent extends AddonBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -25,54 +25,6 @@ public class AddonEvent {
return new AddonEventBuilder();
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.addon.AddonEnableEvent}
*/
@Deprecated
public class AddonEnableEvent extends AddonBaseEvent {
private AddonEnableEvent(Addon addon, Map<String, Object> keyValues) {
// Final variables have to be declared in the constructor
super(addon, keyValues);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.addon.AddonDisableEvent}
*/
@Deprecated
public class AddonDisableEvent extends AddonBaseEvent {
private AddonDisableEvent(Addon addon, Map<String, Object> keyValues) {
// Final variables have to be declared in the constructor
super(addon, keyValues);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.addon.AddonLoadEvent}
*/
@Deprecated
public class AddonLoadEvent extends AddonBaseEvent {
private AddonLoadEvent(Addon addon, Map<String, Object> keyValues) {
// Final variables have to be declared in the constructor
super(addon, keyValues);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.addon.AddonGeneralEvent}
*/
@Deprecated
public class AddonGeneralEvent extends AddonBaseEvent {
private AddonGeneralEvent(Addon addon, Map<String, Object> keyValues) {
// Final variables have to be declared in the constructor
super(addon, keyValues);
}
}
public class AddonEventBuilder {
// Here field are NOT final. They are just used for the building.
private Addon addon;
@ -99,21 +51,12 @@ public class AddonEvent {
return this;
}
private AddonBaseEvent getDeprecatedEvent() {
return switch (reason) {
case ENABLE -> new AddonEnableEvent(addon, keyValues);
case DISABLE -> new AddonDisableEvent(addon, keyValues);
case LOAD -> new AddonLoadEvent(addon, keyValues);
default -> new AddonGeneralEvent(addon, keyValues);
};
}
private AddonBaseEvent getEvent() {
return switch (reason) {
case ENABLE -> new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues);
case DISABLE -> new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues);
case LOAD -> new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues);
default -> new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues);
case ENABLE -> new AddonEnableEvent(addon, keyValues);
case DISABLE -> new AddonDisableEvent(addon, keyValues);
case LOAD -> new AddonLoadEvent(addon, keyValues);
default -> new AddonGeneralEvent(addon, keyValues);
};
}
@ -125,12 +68,7 @@ public class AddonEvent {
// Call new event
AddonBaseEvent newEvent = getEvent();
Bukkit.getPluginManager().callEvent(newEvent);
// Get the old event
AddonBaseEvent e = getDeprecatedEvent();
e.setNewEvent(newEvent);
// Call deprecated event
Bukkit.getPluginManager().callEvent(e);
return e;
return newEvent;
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.Map;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
/**
@ -16,7 +17,7 @@ public class AddonGeneralEvent extends AddonBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.Map;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
/**
@ -16,7 +17,7 @@ public class AddonLoadEvent extends AddonBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.BentoBoxEvent;
/**
@ -24,7 +25,7 @@ public class CommandEvent extends BentoBoxEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.UUID;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.database.objects.Island;
@ -18,7 +19,7 @@ public class FlagProtectionChangeEvent extends FlagChangeEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.UUID;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.database.objects.Island;
@ -18,7 +19,7 @@ public class FlagSettingChangeEvent extends FlagChangeEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.World;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.flags.Flag;
/**
@ -18,7 +19,7 @@ public class FlagWorldSettingChangeEvent extends FlagChangeEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -19,7 +20,7 @@ public class IslandBanEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -20,7 +20,7 @@ public class IslandCreateEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -16,7 +17,7 @@ public class IslandCreatedEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.IslandDeletion;
@ -19,7 +20,7 @@ public class IslandDeleteChunksEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandDeleteEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.IslandDeletion;
@ -21,7 +22,7 @@ public class IslandDeletedEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
@ -20,7 +21,7 @@ public class IslandEnterEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
@ -28,7 +29,7 @@ public class IslandEnterEvent extends IslandBaseEvent {
return handlers;
}
IslandEnterEvent(Island island, UUID player, boolean admin, Location location, Island fromIsland, Event rawEvent) {
IslandEnterEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island fromIsland, Event rawEvent) {
// Final variables have to be declared in the constructor
super(island, player, admin, location, rawEvent);
this.fromIsland = fromIsland;

View File

@ -7,7 +7,6 @@ import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
@ -26,7 +25,7 @@ public class IslandEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
@ -177,496 +176,6 @@ public class IslandEvent extends IslandBaseEvent {
return new IslandEventBuilder();
}
/**
* Fired when a player's rank has changed on an island.
* Cancellation has no effect.
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandRankChangeEvent}
* @since 1.13.0
*/
@Deprecated
public static class IslandRankChangeEvent extends IslandBaseEvent {
private final int oldRank;
private final int newRank;
public IslandRankChangeEvent(Island island, UUID playerUUID, boolean admin, Location location, int oldRank, int newRank) {
super(island, playerUUID, admin, location);
this.oldRank = oldRank;
this.newRank = newRank;
}
public int getOldRank() {
return oldRank;
}
public int getNewRank(){
return newRank;
}
}
/**
* Fired when a player will be expelled from an island.
* May be cancelled.
* Cancellation will result in the expel being aborted.
*
* @since 1.4.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandExpelEvent}
*/
@Deprecated
public static class IslandExpelEvent extends IslandBaseEvent {
private IslandExpelEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when a player will be banned from an island.
* May be cancelled.
* Cancellation will result in the ban being aborted.
*
* @since 1.1
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandBanEvent}
*/
@Deprecated
public static class IslandBanEvent extends IslandBaseEvent {
private IslandBanEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when a player will be banned from an island.
* May be cancelled.
* Cancellation will result in the unban being aborted.
*
* @since 1.1
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandUnbanEvent}
*/
@Deprecated
public static class IslandUnbanEvent extends IslandBaseEvent {
public IslandUnbanEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when attempting to make a new island.
* May be cancelled. No island object exists at this point.
* @since 1.15.1
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandPreCreateEvent}
*/
@Deprecated
public static class IslandPreCreateEvent extends IslandBaseEvent {
private IslandPreCreateEvent(UUID player) {
// Final variables have to be declared in the constructor
super(null, player, false, null);
}
}
/**
* Fired when an island is going to be created.
* May be cancelled.
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandCreateEvent}
*/
@Deprecated
public static class IslandCreateEvent extends IslandBaseEvent {
private @NonNull BlueprintBundle blueprintBundle;
private IslandCreateEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.blueprintBundle = blueprintBundle;
}
/**
* @since 1.6.0
*/
@NonNull
public BlueprintBundle getBlueprintBundle() {
return blueprintBundle;
}
/**
* @since 1.6.0
*/
public void setBlueprintBundle(@NonNull BlueprintBundle blueprintBundle) {
this.blueprintBundle = blueprintBundle;
}
}
/**
* Fired when an island is created.
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandCreatedEvent}
*/
@Deprecated
public static class IslandCreatedEvent extends IslandBaseEvent {
private IslandCreatedEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when an island is going to be deleted.
* May be cancelled.
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandDeleteEvent}
*/
@Deprecated
public static class IslandDeleteEvent extends IslandBaseEvent {
private IslandDeleteEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when an island chunks are going to be deleted.
* May be cancelled.
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent}
*/
@Deprecated
public static class IslandDeleteChunksEvent extends IslandBaseEvent {
private final IslandDeletion deletedIslandInfo;
private IslandDeleteChunksEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.deletedIslandInfo = deletedIsland;
}
public IslandDeletion getDeletedIslandInfo() {
return deletedIslandInfo;
}
}
/**
* Fired when island blocks are going to be deleted.
* If canceled, the island blocks will not be deleted. Note that by the time this is called
* the ownership of the island may have been removed. This event is just for detecting
* that the island blocks are going to be removed.
*
* @deprecated This event is moving to its own class.
*
*/
@Deprecated
public static class IslandDeletedEvent extends IslandBaseEvent {
private final IslandDeletion deletedIslandInfo;
private IslandDeletedEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.deletedIslandInfo = deletedIsland;
}
public IslandDeletion getDeletedIslandInfo() {
return deletedIslandInfo;
}
}
/**
* Fired when a player is unregistered from an island.
* @since 1.3.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent}
*/
@Deprecated
public static class IslandUnregisteredEvent extends IslandBaseEvent {
private IslandUnregisteredEvent(Island island, UUID player, boolean admin, Location location) {
super(island, player, admin, location);
}
}
/**
* Fired when a player is registered from an island.
* @since 1.3.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandRegisteredEvent}
*/
@Deprecated
public static class IslandRegisteredEvent extends IslandBaseEvent {
private IslandRegisteredEvent(Island island, UUID player, boolean admin, Location location) {
super(island, player, admin, location);
}
}
/**
* Fired when an island is reserved for a player
* @since 1.12.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandReservedEvent}
*/
@Deprecated
public static class IslandReservedEvent extends IslandBaseEvent {
private IslandReservedEvent(Island island, UUID player, boolean admin, Location location) {
super(island, player, admin, location);
}
}
/**
* Fired when an a player enters an island.
* Cancellation has no effect.
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandEnterEvent}
*/
@Deprecated
public static class IslandEnterEvent extends IslandBaseEvent {
private final @Nullable Island fromIsland;
private IslandEnterEvent(Island island, UUID player, boolean admin, Location location, Island fromIsland, Event rawEvent) {
// Final variables have to be declared in the constructor
super(island, player, admin, location, rawEvent);
this.fromIsland = fromIsland;
}
@Nullable
public Island getFromIsland() {
return fromIsland;
}
}
/**
* Fired when a player exits an island.
* Cancellation has no effect.
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandExitEvent}
*/
@Deprecated
public static class IslandExitEvent extends IslandBaseEvent {
private final @Nullable Island toIsland;
private IslandExitEvent(Island island, UUID player, boolean admin, Location location, Island toIsland, Event rawEvent) {
// Final variables have to be declared in the constructor
super(island, player, admin, location, rawEvent);
this.toIsland = toIsland;
}
@Nullable
public Island getToIsland() {
return toIsland;
}
}
/**
* Fired when an island is locked
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandLockEvent}
*/
@Deprecated
public static class IslandLockEvent extends IslandBaseEvent {
private IslandLockEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when an island is unlocked
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandUnlockEvent}
*/
@Deprecated
public static class IslandUnlockEvent extends IslandBaseEvent {
private IslandUnlockEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired before an island has its player data cleared, e.g., just before a reset
* @since 1.12.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandPreclearEvent}
*/
@Deprecated
public static class IslandPreclearEvent extends IslandBaseEvent {
private final @NonNull Island oldIsland;
private IslandPreclearEvent(Island island, UUID player, boolean admin, Location location, @NonNull Island oldIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
// Create a copy of the old island
this.oldIsland = new Island(oldIsland);
}
/**
* @since 1.12.0
*/
@NonNull
public Island getOldIsland() {
return oldIsland;
}
}
/**
* Fired when an island is going to be reset.
* May be cancelled.
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandResetEvent}
*/
@Deprecated
public static class IslandResetEvent extends IslandBaseEvent {
private final @NonNull Island oldIsland;
private @NonNull BlueprintBundle blueprintBundle;
private IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle, @NonNull Island oldIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.blueprintBundle = blueprintBundle;
// Create a copy of the old island
this.oldIsland = new Island(oldIsland);
}
/**
* @since 1.12.0
*/
@NonNull
public Island getOldIsland() {
return oldIsland;
}
/**
* @since 1.6.0
*/
@NonNull
public BlueprintBundle getBlueprintBundle() {
return blueprintBundle;
}
/**
* @since 1.6.0
*/
public void setBlueprintBundle(@NonNull BlueprintBundle blueprintBundle) {
this.blueprintBundle = blueprintBundle;
}
}
/**
* Fired after an island is reset
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandResettedEvent}
*/
@Deprecated
public static class IslandResettedEvent extends IslandBaseEvent {
private final @NonNull Island oldIsland;
private IslandResettedEvent(Island island, UUID player, boolean admin, Location location, Island oldIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
// Create a copy of the old island
this.oldIsland = new Island(oldIsland);
}
/**
* @since 1.12.0
*/
@NonNull
public Island getOldIsland() {
return oldIsland;
}
}
/**
* Fired when something happens to the island not covered by other events
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandGeneralEvent}
*/
@Deprecated
public static class IslandGeneralEvent extends IslandBaseEvent {
private IslandGeneralEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Fired when island protection range is changed.
* @since 1.11.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent}
*/
@Deprecated
public static class IslandProtectionRangeChangeEvent extends IslandBaseEvent {
/**
* New protection range value.
*/
private int newRange;
/**
* Old protection range value.
*/
private int oldRange;
/**
* Constructor IslandProtectionRangeChange creates a new IslandProtectionRangeChange instance.
*
* @param island of type Island
* @param player of type UUID
* @param admin of type boolean
* @param location of type Location
* @param newRange of type int
* @param oldRange of type int
*/
private IslandProtectionRangeChangeEvent(Island island, UUID player, boolean admin, Location location, int newRange, int oldRange) {
super(island, player, admin, location);
this.newRange = newRange;
this.oldRange = oldRange;
}
/**
* This method returns the newRange value.
* @return the value of newRange.
*/
public int getNewRange() {
return newRange;
}
/**
* This method returns the oldRange value.
* @return the value of oldRange.
*/
public int getOldRange() {
return oldRange;
}
/**
* This method sets the newRange value.
* @param newRange the newRange new value.
*/
public void setNewRange(int newRange) {
this.newRange = newRange;
}
/**
* This method sets the oldRange value.
* @param oldRange the oldRange new value.
*/
public void setOldRange(int oldRange) {
this.oldRange = oldRange;
}
}
public static class IslandEventBuilder {
// Here field are NOT final. They are just used for the building.
@ -796,62 +305,31 @@ public class IslandEvent extends IslandBaseEvent {
return this;
}
/**
* Get the deprecated IslandEvent
* @return deprecated event
*/
private IslandBaseEvent getDeprecatedEvent() {
return switch (reason) {
case EXPEL -> new IslandExpelEvent(island, player, admin, location);
case BAN -> new IslandBanEvent(island, player, admin, location);
case PRECREATE -> new IslandPreCreateEvent(player);
case CREATE -> new IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED -> new IslandCreatedEvent(island, player, admin, location);
case DELETE -> new IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS -> new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED -> new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER -> new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT -> new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK -> new IslandLockEvent(island, player, admin, location);
case RESET -> new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED -> new IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN -> new IslandUnbanEvent(island, player, admin, location);
case UNLOCK -> new IslandUnlockEvent(island, player, admin, location);
case REGISTERED -> new IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED -> new IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE -> new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR -> new IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED -> new IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE -> new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
default -> new IslandGeneralEvent(island, player, admin, location);
};
}
private IslandBaseEvent getEvent() {
return switch (reason) {
case EXPEL -> new world.bentobox.bentobox.api.events.island.IslandExpelEvent(island, player, admin, location);
case BAN -> new world.bentobox.bentobox.api.events.island.IslandBanEvent(island, player, admin, location);
case PRECREATE -> new world.bentobox.bentobox.api.events.island.IslandPreCreateEvent(player);
case CREATE -> new world.bentobox.bentobox.api.events.island.IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED -> new world.bentobox.bentobox.api.events.island.IslandCreatedEvent(island, player, admin, location);
case DELETE -> new world.bentobox.bentobox.api.events.island.IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS -> new world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED -> new world.bentobox.bentobox.api.events.island.IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER -> new world.bentobox.bentobox.api.events.island.IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT -> new world.bentobox.bentobox.api.events.island.IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK -> new world.bentobox.bentobox.api.events.island.IslandLockEvent(island, player, admin, location);
case RESET -> new world.bentobox.bentobox.api.events.island.IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED -> new world.bentobox.bentobox.api.events.island.IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN -> new world.bentobox.bentobox.api.events.island.IslandUnbanEvent(island, player, admin, location);
case UNLOCK -> new world.bentobox.bentobox.api.events.island.IslandUnlockEvent(island, player, admin, location);
case REGISTERED -> new world.bentobox.bentobox.api.events.island.IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED -> new world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR -> new world.bentobox.bentobox.api.events.island.IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED -> new world.bentobox.bentobox.api.events.island.IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
case NEW_ISLAND -> new IslandNewIslandEvent(island, player, admin, location);
default -> new world.bentobox.bentobox.api.events.island.IslandGeneralEvent(island, player, admin, location);
case EXPEL -> new IslandExpelEvent(island, player, admin, location);
case BAN -> new IslandBanEvent(island, player, admin, location);
case PRECREATE -> new IslandPreCreateEvent(player);
case CREATE -> new IslandCreateEvent(island, player, admin, location, blueprintBundle);
case CREATED -> new IslandCreatedEvent(island, player, admin, location);
case DELETE -> new IslandDeleteEvent(island, player, admin, location);
case DELETE_CHUNKS -> new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
case DELETED -> new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
case ENTER -> new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
case EXIT -> new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
case LOCK -> new IslandLockEvent(island, player, admin, location);
case RESET -> new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
case RESETTED -> new IslandResettedEvent(island, player, admin, location, oldIsland);
case UNBAN -> new IslandUnbanEvent(island, player, admin, location);
case UNLOCK -> new IslandUnlockEvent(island, player, admin, location);
case REGISTERED -> new IslandRegisteredEvent(island, player, admin, location);
case UNREGISTERED -> new IslandUnregisteredEvent(island, player, admin, location);
case RANGE_CHANGE -> new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange);
case PRECLEAR -> new IslandPreclearEvent(island, player, admin, location, oldIsland);
case RESERVED -> new IslandReservedEvent(island, player, admin, location);
case RANK_CHANGE -> new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
case NEW_ISLAND -> new IslandNewIslandEvent(island, player, admin, location);
default -> new IslandGeneralEvent(island, player, admin, location);
};
}
@ -865,11 +343,7 @@ public class IslandEvent extends IslandBaseEvent {
// Generate new event
IslandBaseEvent newEvent = getEvent();
Bukkit.getPluginManager().callEvent(newEvent);
// Generate deprecated events
IslandBaseEvent e = getDeprecatedEvent();
e.setNewEvent(newEvent);
Bukkit.getPluginManager().callEvent(e);
return e;
return newEvent;
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
@ -20,7 +21,7 @@ public class IslandExitEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
@ -28,7 +29,7 @@ public class IslandExitEvent extends IslandBaseEvent {
return handlers;
}
IslandExitEvent(Island island, UUID player, boolean admin, Location location, Island toIsland, Event rawEvent) {
IslandExitEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island toIsland, Event rawEvent) {
// Final variables have to be declared in the constructor
super(island, player, admin, location, rawEvent);
this.toIsland = toIsland;

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -20,7 +21,7 @@ public class IslandExpelEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandGeneralEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandLockEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandNewIslandEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -4,6 +4,7 @@ import java.util.UUID;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
/**
@ -16,7 +17,7 @@ public class IslandPreCreateEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -19,7 +19,7 @@ public class IslandPreclearEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandProtectionRangeChangeEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -20,7 +21,7 @@ public class IslandRankChangeEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandRegisteredEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandReservedEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -21,7 +21,7 @@ public class IslandResetEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -19,7 +19,7 @@ public class IslandResettedEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -20,7 +21,7 @@ public class IslandUnbanEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandUnlockEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class IslandUnregisteredEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamDeleteEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -36,161 +36,6 @@ public class TeamEvent {
return new TeamEventBuilder();
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamJoinEvent}
*/
@Deprecated
public static class TeamJoinEvent extends IslandBaseEvent {
private TeamJoinEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Called after a player has joined an island
* @since 1.3.0
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamJoinedEvent}
*/
@Deprecated
public static class TeamJoinedEvent extends IslandBaseEvent {
/**
* Called after a player has joined an island
* @param island - island
* @param player - player
* @param admin - whether this was due to an admin action
* @param location - location
* @since 1.3.0
*/
private TeamJoinedEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamInviteEvent}
*/
@Deprecated
public static class TeamInviteEvent extends IslandBaseEvent {
private TeamInviteEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamLeaveEvent}
*/
@Deprecated
public static class TeamLeaveEvent extends IslandBaseEvent {
private TeamLeaveEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamRejectEvent}
*/
@Deprecated
public static class TeamRejectEvent extends IslandBaseEvent {
private TeamRejectEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamKickEvent}
*/
@Deprecated
public static class TeamKickEvent extends IslandBaseEvent {
private TeamKickEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* Event fires before a setowner is performed on an island.
* To get the old owner, get from the island object. The new owner is the player's UUID.
* @author tastybento
*
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamSetownerEvent}
*/
@Deprecated
public static class TeamSetownerEvent extends IslandBaseEvent {
private TeamSetownerEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
/**
* Convenience method to get the old owner of the island
* @return UUID of old owner
*/
public UUID getOldOwner() {
return island.getOwner();
}
/**
* Convenience method to get the new owner of the island
* @return UUID of new owner
*/
public UUID getNewOwner() {
return playerUUID;
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamInfoEvent}
*/
@Deprecated
public static class TeamInfoEvent extends IslandBaseEvent {
private TeamInfoEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamDeleteEvent}
*/
@Deprecated
public static class TeamDeleteEvent extends IslandBaseEvent {
private TeamDeleteEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamUninviteEvent}
*/
@Deprecated
public static class TeamUninviteEvent extends IslandBaseEvent {
private TeamUninviteEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
/**
* @deprecated This event is moving to its own class.
* Use {@link world.bentobox.bentobox.api.events.team.TeamGeneralEvent}
*/
@Deprecated
public static class TeamGeneralEvent extends IslandBaseEvent {
private TeamGeneralEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
public static class TeamEventBuilder {
private Island island;
private UUID player;
@ -236,35 +81,19 @@ public class TeamEvent {
return this;
}
private IslandBaseEvent getDeprecatedEvent() {
return switch (reason) {
case JOIN -> new TeamJoinEvent(island, player, admin, location);
case JOINED -> new TeamJoinedEvent(island, player, admin, location);
case INVITE -> new TeamInviteEvent(island, player, admin, location);
case LEAVE -> new TeamLeaveEvent(island, player, admin, location);
case REJECT -> new TeamRejectEvent(island, player, admin, location);
case KICK -> new TeamKickEvent(island, player, admin, location);
case SETOWNER -> new TeamSetownerEvent(island, player, admin, location);
case INFO -> new TeamInfoEvent(island, player, admin, location);
case DELETE -> new TeamDeleteEvent(island, player, admin, location);
case UNINVITE -> new TeamUninviteEvent(island, player, admin, location);
default -> new TeamGeneralEvent(island, player, admin, location);
};
}
private IslandBaseEvent getEvent() {
return switch (reason) {
case JOIN -> new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location);
case JOINED -> new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location);
case INVITE -> new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location);
case LEAVE -> new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location);
case REJECT -> new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location);
case KICK -> new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location);
case SETOWNER -> new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location);
case INFO -> new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location);
case DELETE -> new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location);
case UNINVITE -> new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location);
default -> new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location);
case JOIN -> new TeamJoinEvent(island, player, admin, location);
case JOINED -> new TeamJoinedEvent(island, player, admin, location);
case INVITE -> new TeamInviteEvent(island, player, admin, location);
case LEAVE -> new TeamLeaveEvent(island, player, admin, location);
case REJECT -> new TeamRejectEvent(island, player, admin, location);
case KICK -> new TeamKickEvent(island, player, admin, location);
case SETOWNER -> new TeamSetownerEvent(island, player, admin, location);
case INFO -> new TeamInfoEvent(island, player, admin, location);
case DELETE -> new TeamDeleteEvent(island, player, admin, location);
case UNINVITE -> new TeamUninviteEvent(island, player, admin, location);
default -> new TeamGeneralEvent(island, player, admin, location);
};
}
@ -276,11 +105,7 @@ public class TeamEvent {
// Generate new event
IslandBaseEvent newEvent = getEvent();
Bukkit.getPluginManager().callEvent(newEvent);
// Generate deprecated events
IslandBaseEvent e = getDeprecatedEvent();
e.setNewEvent(newEvent);
Bukkit.getPluginManager().callEvent(e);
return e;
return newEvent;
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamGeneralEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamInfoEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamInviteEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamJoinEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -17,7 +18,7 @@ public class TeamJoinedEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamKickEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -18,7 +19,7 @@ public class TeamLeaveEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamRejectEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -19,7 +20,7 @@ public class TeamSetownerEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -13,7 +14,7 @@ public class TeamUninviteEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}

View File

@ -175,8 +175,10 @@ public class Flag implements Comparable<Flag> {
* If world is not a game world, then the result will always be false!
*/
public boolean isSetForWorld(World world) {
if (!BentoBox.getInstance().getIWM().inWorld(world)) {
return false;
}
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
if (ws == null) return false;
if (type.equals(Type.WORLD_SETTING) || type.equals(Type.PROTECTION)) {
if (!ws.getWorldFlags().containsKey(getID())) {
ws.getWorldFlags().put(getID(), setting);
@ -234,12 +236,11 @@ public class Flag implements Comparable<Flag> {
* @param defaultSetting - true means it is allowed. false means it is not allowed
*/
public void setDefaultSetting(World world, boolean defaultSetting) {
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
if (ws == null ) {
if (!BentoBox.getInstance().getIWM().inWorld(world)) {
BentoBox.getInstance().logError("Attempt to set default world setting for unregistered world. Register flags in onEnable.");
return;
}
ws.getWorldFlags().put(getID(), defaultSetting);
BentoBox.getInstance().getIWM().getWorldSettings(world).getWorldFlags().put(getID(), defaultSetting);
// Save config file
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
}

View File

@ -126,9 +126,9 @@ public abstract class FlagListener implements Listener {
*/
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @Nullable Location loc, @NonNull Flag flag, boolean silent) {
// Set user
user = User.getInstance(player);
user = player == null ? null : User.getInstance(player);
if (loc == null) {
if (user.getLocation() != null && user.getLocation().getWorld() != null) {
if (user != null && user.getLocation() != null && user.getLocation().getWorld() != null) {
report(user, e, user.getLocation(), flag, Why.NULL_LOCATION);
}
return true;

View File

@ -24,7 +24,7 @@ import world.bentobox.bentobox.util.Util;
*/
public class CycleClick implements PanelItem.ClickHandler {
protected BentoBox plugin = BentoBox.getInstance();
protected final BentoBox plugin = BentoBox.getInstance();
protected Island island;
protected User user;
protected boolean changeOccurred;

View File

@ -34,4 +34,8 @@ public class TextVariables {
* @since 1.16.0
*/
public static final String XYZ = "[xyz]";
/**
* @since 1.17.2
*/
public static final String UUID = "[uuid]";
}

View File

@ -137,7 +137,7 @@ public class PanelItemBuilder {
/**
* @return the name
*/
public String getName() {
public @Nullable String getName() {
return name;
}

View File

@ -32,6 +32,14 @@ import world.bentobox.bentobox.util.ItemParser;
*/
public class TemplateReader
{
private static final String TITLE = "title";
private static final String ICON = "icon";
private static final String DESCRIPTION = "description";
private static final String BACKGROUND = "background";
private static final String BORDER = "border";
private static final String FORCE_SHOWN = "force-shown";
private static final String FALLBACK = "fallback";
/**
* Read template panel panel template record.
*
@ -95,57 +103,57 @@ public class TemplateReader
return null;
}
String title = configurationSection.getString("title");
String title = configurationSection.getString(TITLE);
Panel.Type type =
Enums.getIfPresent(Panel.Type.class, configurationSection.getString("type", "INVENTORY")).
Enums.getIfPresent(Panel.Type.class, configurationSection.getString("type", "INVENTORY")).
or(Panel.Type.INVENTORY);
PanelTemplateRecord.TemplateItem borderItem = null;
// Read Border Icon.
if (configurationSection.isConfigurationSection("border"))
if (configurationSection.isConfigurationSection(BORDER))
{
// Process border icon if it contains more options.
ConfigurationSection borderSection = configurationSection.getConfigurationSection("border");
ConfigurationSection borderSection = configurationSection.getConfigurationSection(BORDER);
if (borderSection != null)
{
borderItem = new PanelTemplateRecord.TemplateItem(
ItemParser.parse((borderSection.getString("icon", Material.AIR.name()))),
borderSection.getString("title", null),
borderSection.getString("description", null));
ItemParser.parse((borderSection.getString(ICON, Material.AIR.name()))),
borderSection.getString(TITLE, null),
borderSection.getString(DESCRIPTION, null));
}
}
else if (configurationSection.isString("border"))
else if (configurationSection.isString(BORDER))
{
// Process border icon if it contains only icon.
borderItem = new PanelTemplateRecord.TemplateItem(
ItemParser.parse((configurationSection.getString("border", Material.AIR.name()))));
ItemParser.parse((configurationSection.getString(BORDER, Material.AIR.name()))));
}
PanelTemplateRecord.TemplateItem backgroundItem = null;
// Read Background block
if (configurationSection.isConfigurationSection("background"))
if (configurationSection.isConfigurationSection(BACKGROUND))
{
// Process border icon if it contains more options.
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection("background");
ConfigurationSection backgroundSection = configurationSection.getConfigurationSection(BACKGROUND);
if (backgroundSection != null)
{
backgroundItem = new PanelTemplateRecord.TemplateItem(
ItemParser.parse((backgroundSection.getString("icon", Material.AIR.name()))),
backgroundSection.getString("title", null),
backgroundSection.getString("description", null));
ItemParser.parse((backgroundSection.getString(ICON, Material.AIR.name()))),
backgroundSection.getString(TITLE, null),
backgroundSection.getString(DESCRIPTION, null));
}
}
else if (configurationSection.isString("background"))
else if (configurationSection.isString(BACKGROUND))
{
// Process background icon if it contains only icon.
backgroundItem = new PanelTemplateRecord.TemplateItem(
ItemParser.parse((configurationSection.getString("background", Material.AIR.name()))));
ItemParser.parse((configurationSection.getString(BACKGROUND, Material.AIR.name()))));
}
// Read reusable
@ -156,7 +164,7 @@ public class TemplateReader
{
// Add all reusables to the local storage.
reusable.getKeys(false).forEach(key ->
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
readPanelItemTemplate(reusable.getConfigurationSection(key), key, panelItemDataMap));
}
// Read content
@ -190,15 +198,15 @@ public class TemplateReader
{
// If it contains a section, then build a new button template from it.
template.addButtonTemplate(rowIndex,
columnIndex,
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
columnIndex,
readPanelItemTemplate(line.getConfigurationSection(String.valueOf(columnIndex + 1))));
}
else if (line.isString(String.valueOf(columnIndex + 1)))
{
// If it contains just a single word, assume it is a reusable.
template.addButtonTemplate(rowIndex,
columnIndex,
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
columnIndex,
panelItemDataMap.get(line.getString(String.valueOf(columnIndex + 1))));
}
}
}
@ -221,20 +229,20 @@ public class TemplateReader
{
boolean[] forceShow = new boolean[6];
if (section != null && section.contains("force-shown"))
if (section != null && section.contains(FORCE_SHOWN))
{
if (section.isInt("force-shown"))
if (section.isInt(FORCE_SHOWN))
{
int value = section.getInt("force-shown");
int value = section.getInt(FORCE_SHOWN);
if (value > 0 && value < 7)
{
forceShow[value-1] = true;
}
}
else if (section.isList("force-shown"))
else if (section.isList(FORCE_SHOWN))
{
section.getIntegerList("force-shown").forEach(number -> {
section.getIntegerList(FORCE_SHOWN).forEach(number -> {
if (number > 0 && number < 7)
{
forceShow[number-1] = true;
@ -267,8 +275,8 @@ public class TemplateReader
*/
@Nullable
private static ItemTemplateRecord readPanelItemTemplate(@Nullable ConfigurationSection section,
String itemKey,
Map<String, ItemTemplateRecord> reusableItemMap)
String itemKey,
Map<String, ItemTemplateRecord> reusableItemMap)
{
if (section == null)
{
@ -278,13 +286,13 @@ public class TemplateReader
ItemTemplateRecord fallback;
if (section.isConfigurationSection("fallback"))
if (section.isConfigurationSection(FALLBACK))
{
fallback = readPanelItemTemplate(section.getConfigurationSection("fallback"));
fallback = readPanelItemTemplate(section.getConfigurationSection(FALLBACK));
}
else if (section.isString("fallback") && reusableItemMap != null)
else if (section.isString(FALLBACK) && reusableItemMap != null)
{
fallback = reusableItemMap.get(section.getString("fallback"));
fallback = reusableItemMap.get(section.getString(FALLBACK));
}
else
{
@ -292,10 +300,10 @@ public class TemplateReader
}
// Create Item Record
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString("icon")),
section.getString("title", null),
section.getString("description", null),
fallback);
ItemTemplateRecord itemRecord = new ItemTemplateRecord(ItemParser.parse(section.getString(ICON)),
section.getString(TITLE, null),
section.getString(DESCRIPTION, null),
fallback);
// Read data
if (section.isConfigurationSection("data"))
@ -325,11 +333,10 @@ public class TemplateReader
if (actionDataSection != null)
{
ItemTemplateRecord.ActionRecords actionData =
new ItemTemplateRecord.ActionRecords(clickType,
actionDataSection.getString("type"),
actionDataSection.getString("content"),
actionDataSection.getString("tooltip"));
new ItemTemplateRecord.ActionRecords(clickType,
actionDataSection.getString("type"),
actionDataSection.getString("content"),
actionDataSection.getString("tooltip"));
itemRecord.addAction(actionData);
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.placeholders.placeholderapi;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
public class AddonPlaceholderExpansion extends BasicPlaceholderExpansion {
@ -10,17 +11,17 @@ public class AddonPlaceholderExpansion extends BasicPlaceholderExpansion {
}
@Override
public String getName() {
public @NonNull String getName() {
return addon.getDescription().getName();
}
@Override
public String getAuthor() {
public @NonNull String getAuthor() {
return addon.getDescription().getAuthors().get(0);
}
@Override
public String getVersion() {
public @NonNull String getVersion() {
return addon.getDescription().getVersion();
}
}

View File

@ -24,7 +24,7 @@ abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
}
@Override
public String getIdentifier() {
public @NonNull String getIdentifier() {
return getName().toLowerCase(Locale.ENGLISH);
}
@ -42,13 +42,13 @@ abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
}
@Override
public String onPlaceholderRequest(Player p, String placeholder) {
if (placeholders.containsKey(placeholder)) {
public String onPlaceholderRequest(Player p, @NonNull String placeholder) {
if (placeholders.containsKey(placeholder) && p != null) {
return placeholders.get(placeholder).onReplace(User.getInstance(p));
}
return null;
}
/**
* Checks if a placeholder with this name is already registered
* @param placeholder - name of placeholder
@ -56,7 +56,7 @@ abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
* @since 1.4.0
*/
public boolean isPlaceholder(@NonNull String placeholder) {
return placeholders.containsKey(placeholder);
return placeholders.containsKey(placeholder);
}
@Override

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.placeholders.placeholderapi;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
public class BentoBoxPlaceholderExpansion extends BasicPlaceholderExpansion {
@ -11,17 +12,17 @@ public class BentoBoxPlaceholderExpansion extends BasicPlaceholderExpansion {
}
@Override
public String getName() {
public @NonNull String getName() {
return plugin.getName();
}
@Override
public String getAuthor() {
public @NonNull String getAuthor() {
return "Tastybento and Poslovitch";
}
@Override
public String getVersion() {
public @NonNull String getVersion() {
return plugin.getDescription().getVersion();
}
}

View File

@ -6,6 +6,7 @@ import java.util.concurrent.TimeUnit;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.eclipse.jdt.annotation.NonNull;
/**
* Utilities class that helps to avoid spamming the User with potential repeated messages
@ -26,7 +27,7 @@ public class Notifier {
.build(
new CacheLoader<>() {
@Override
public Notification load(User user) {
public Notification load(@NonNull User user) {
return new Notification(null, 0);
}
}

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@ -32,6 +33,7 @@ import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.events.OfflineMessageEvent;
import world.bentobox.bentobox.api.metadata.MetaDataAble;
import world.bentobox.bentobox.api.metadata.MetaDataValue;
import world.bentobox.bentobox.database.objects.Players;
import world.bentobox.bentobox.util.Util;
/**
@ -61,25 +63,22 @@ public class User implements MetaDataAble {
* @param sender - command sender, e.g. console
* @return user - user
*/
@Nullable
public static User getInstance(CommandSender sender) {
if (sender instanceof Player) {
return getInstance((Player)sender);
@NonNull
public static User getInstance(@NonNull CommandSender sender) {
if (sender instanceof Player p) {
return getInstance(p);
}
// Console
return new User(sender);
}
/**
* Gets an instance of User from a Player object
* Gets an instance of User from a Player object.
* @param player - the player
* @return user - user
*/
@Nullable
public static User getInstance(Player player) {
if (player == null) {
return null;
}
@NonNull
public static User getInstance(@NonNull Player player) {
if (users.containsKey(player.getUniqueId())) {
return users.get(player.getUniqueId());
}
@ -87,15 +86,12 @@ public class User implements MetaDataAble {
}
/**
* Gets an instance of User from a UUID
* Gets an instance of User from a UUID.
* @param uuid - UUID
* @return user - user
*/
@Nullable
public static User getInstance(@Nullable UUID uuid) {
if (uuid == null) {
return null;
}
@NonNull
public static User getInstance(@NonNull UUID uuid) {
if (users.containsKey(uuid)) {
return users.get(uuid);
}
@ -109,11 +105,8 @@ public class User implements MetaDataAble {
* @return user
* @since 1.3.0
*/
@Nullable
public static User getInstance(OfflinePlayer offlinePlayer) {
if (offlinePlayer == null) {
return null;
}
@NonNull
public static User getInstance(@NonNull OfflinePlayer offlinePlayer) {
if (users.containsKey(offlinePlayer.getUniqueId())) {
return users.get(offlinePlayer.getUniqueId());
}
@ -144,7 +137,7 @@ public class User implements MetaDataAble {
private Addon addon;
private User(CommandSender sender) {
private User(@Nullable CommandSender sender) {
player = null;
playerUUID = null;
this.sender = sender;
@ -184,25 +177,42 @@ public class User implements MetaDataAble {
return sender.getEffectivePermissions();
}
@Nullable
/**
* Get the user's inventory
* @return player's inventory
* @throws {@link NullPointerException} - if user is not a player
*/
@NonNull
public PlayerInventory getInventory() {
return player != null ? player.getInventory() : null;
return Objects.requireNonNull(player, "getInventory can only be called for online players!").getInventory();
}
@Nullable
/**
* Get the user's location
* @return location
* @throws {@link NullPointerException} - if user is not a player
*/
@NonNull
public Location getLocation() {
return player != null ? player.getLocation() : null;
return Objects.requireNonNull(player, "getLocation can only be called for online players!").getLocation();
}
/**
* Get the user's name
* @return player's name
*/
@NonNull
public String getName() {
return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID);
}
/**
* Check if the User is a player before calling this method. {@link #isPlayer()}
* @return the player
*/
@NonNull
public Player getPlayer() {
return player;
return Objects.requireNonNull(player, "User is not a player!");
}
/**
@ -213,11 +223,14 @@ public class User implements MetaDataAble {
}
/**
* Use {@link #isOfflinePlayer()} before calling this method
* @return the offline player
* @since 1.3.0
* @throws {@link NullPointerException} - if user is not an offline player
*/
@NonNull
public OfflinePlayer getOfflinePlayer() {
return offlinePlayer;
return Objects.requireNonNull(offlinePlayer, "User is not an OfflinePlayer!");
}
/**
@ -354,11 +367,11 @@ public class User implements MetaDataAble {
// Get translation.
String addonPrefix = plugin.getIWM()
.getAddon(world).map(a -> a.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".").orElse("");
return translate(addonPrefix, reference, variables);
return Util.translateColorCodes(translate(addonPrefix, reference, variables));
}
/**
* Gets a translation of this reference for this user. Translations may be overridden by Addons
* Gets a translation of this reference for this user with colors converted. Translations may be overridden by Addons
* by using the same reference prefixed by the addon name (from the Addon Description) in lower case.
* @param reference - reference found in a locale file
* @param variables - variables to insert into translated string. Variables go in pairs, for example
@ -366,6 +379,21 @@ public class User implements MetaDataAble {
* @return Translated string with colors converted, or the reference if nothing has been found
*/
public String getTranslation(String reference, String... variables) {
// Get addonPrefix
String addonPrefix = addon == null ? "" : addon.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".";
return Util.translateColorCodes(translate(addonPrefix, reference, variables));
}
/**
* Gets a translation of this reference for this user without colors translated. Translations may be overridden by Addons
* by using the same reference prefixed by the addon name (from the Addon Description) in lower case.
* @param reference - reference found in a locale file
* @param variables - variables to insert into translated string. Variables go in pairs, for example
* "[name]", "tastybento"
* @return Translated string or the reference if nothing has been found
* @since 1.17.4
*/
public String getTranslationNoColor(String reference, String... variables) {
// Get addonPrefix
String addonPrefix = addon == null ? "" : addon.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".";
return translate(addonPrefix, reference, variables);
@ -392,7 +420,7 @@ public class User implements MetaDataAble {
// Replace the [gamemode] text variable
prefixTranslation = prefixTranslation.replace("[gamemode]", addon != null ? addon.getDescription().getName() : "[gamemode]");
// Replace the [friendly_name] text variable
prefixTranslation = prefixTranslation.replace("[friendly_name]", getWorld() != null ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
prefixTranslation = prefixTranslation.replace("[friendly_name]", isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
// Replace the prefix in the actual message
translation = translation.replace("[prefix_" + prefix + "]", prefixTranslation);
@ -410,7 +438,7 @@ public class User implements MetaDataAble {
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
}
return Util.translateColorCodes(translation);
return translation;
}
}
@ -499,10 +527,13 @@ public class User implements MetaDataAble {
/**
* Gets the current world this entity resides in
* @return World - world or null
* @return World - world
* @throws {@link NullPointerException} - if user is not a player
*/
@NonNull
public World getWorld() {
return player == null ? null : player.getWorld();
Objects.requireNonNull(player, "Cannot be called on a non-player User!");
return Objects.requireNonNull(player.getWorld(), "Player's world cannot be null!");
}
/**
@ -641,10 +672,10 @@ public class User implements MetaDataAble {
*/
@Override
public Optional<Map<String, MetaDataValue>> getMetaData() {
return plugin
Players p = plugin
.getPlayers()
.getPlayer(playerUUID)
.getMetaData();
.getPlayer(playerUUID);
return Objects.requireNonNull(p, "Unknown player for " + playerUUID).getMetaData();
}
/**
@ -653,7 +684,11 @@ public class User implements MetaDataAble {
*/
@Override
public void setMetaData(Map<String, MetaDataValue> metaData) {
plugin.getPlayers().getPlayer(playerUUID).setMetaData(metaData);
Players p = plugin
.getPlayers()
.getPlayer(playerUUID);
Objects.requireNonNull(p, "Unknown player for " + playerUUID).setMetaData(metaData);
}
}

View File

@ -79,7 +79,7 @@ public class Blueprint {
/**
* @return the icon
*/
public Material getIcon() {
public @NonNull Material getIcon() {
return icon;
}
/**

View File

@ -139,7 +139,7 @@ public class BlueprintClipboard {
Math.rint(e.getLocation().getY()),
Math.rint(e.getLocation().getZ())).equals(v))
.collect(Collectors.toList());
if (copyBlock(v.toLocation(world), origin, copyAir, ents)) {
if (copyBlock(v.toLocation(world), copyAir, ents)) {
count++;
}
});
@ -151,6 +151,7 @@ public class BlueprintClipboard {
}
if (index > vectorsToCopy.size()) {
copyTask.cancel();
assert blueprint != null;
blueprint.setAttached(bpAttachable);
blueprint.setBlocks(bpBlocks);
blueprint.setEntities(bpEntities);
@ -178,12 +179,13 @@ public class BlueprintClipboard {
return r;
}
private boolean copyBlock(Location l, @Nullable Vector origin2, boolean copyAir, Collection<LivingEntity> entities) {
private boolean copyBlock(Location l, boolean copyAir, Collection<LivingEntity> entities) {
Block block = l.getBlock();
if (!copyAir && block.getType().equals(Material.AIR) && entities.isEmpty()) {
return false;
}
// Create position
Vector origin2 = origin == null ? new Vector(0,0,0) : origin;
int x = l.getBlockX() - origin2.getBlockX();
int y = l.getBlockY() - origin2.getBlockY();
int z = l.getBlockZ() - origin2.getBlockZ();
@ -398,7 +400,7 @@ public class BlueprintClipboard {
/**
* @return the blueprint
*/
public Blueprint getBlueprint() {
public @Nullable Blueprint getBlueprint() {
return blueprint;
}

View File

@ -109,7 +109,7 @@ public class BlueprintPaster {
this.plugin = plugin;
this.clipboard = clipboard;
// Calculate location for pasting
this.blueprint = clipboard.getBlueprint();
this.blueprint = Objects.requireNonNull(clipboard.getBlueprint(), "Clipboard cannot have a null Blueprint");
this.location = location;
this.island = null;
@ -416,9 +416,11 @@ public class BlueprintPaster {
if (island != null && !lines.isEmpty() && lines.get(0).equalsIgnoreCase(TextVariables.START_TEXT)) {
// Get the addon that is operating in this world
String addonName = plugin.getIWM().getAddon(island.getWorld()).map(addon -> addon.getDescription().getName().toLowerCase(Locale.ENGLISH)).orElse("");
for (int i = 0; i < 4; i++) {
s.setLine(i, Util.translateColorCodes(plugin.getLocalesManager().getOrDefault(User.getInstance(island.getOwner()),
addonName + ".sign.line" + i,"").replace(TextVariables.NAME, name)));
if (island.getOwner() != null) {
for (int i = 0; i < 4; i++) {
s.setLine(i, Util.translateColorCodes(plugin.getLocalesManager().getOrDefault(User.getInstance(island.getOwner()),
addonName + ".sign.line" + i,"").replace(TextVariables.NAME, name)));
}
}
} else {
// Just paste

View File

@ -8,6 +8,7 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@ -33,7 +34,7 @@ public class DescriptionPrompt extends StringPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(ConversationContext context) {
public @NonNull String getPromptText(ConversationContext context) {
User user = User.getInstance((Player)context.getForWhom());
if (context.getSessionData(DESCRIPTION) != null) {
StringBuilder sb = new StringBuilder();

View File

@ -7,6 +7,7 @@ import org.bukkit.conversations.MessagePrompt;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.user.User;
@ -28,7 +29,7 @@ public class DescriptionSuccessPrompt extends MessagePrompt {
}
@Override
public String getPromptText(ConversationContext context) {
public @NonNull String getPromptText(ConversationContext context) {
User user = User.getInstance((Player)context.getForWhom());
@SuppressWarnings("unchecked")
List<String> description = (List<String>)context.getSessionData("description");
@ -46,7 +47,7 @@ public class DescriptionSuccessPrompt extends MessagePrompt {
}
@Override
protected Prompt getNextPrompt(ConversationContext context) {
protected Prompt getNextPrompt(@NonNull ConversationContext context) {
return Prompt.END_OF_CONVERSATION;
}

View File

@ -4,12 +4,13 @@ import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.ConversationPrefix;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.user.User;
public class NameConversationPrefix implements ConversationPrefix {
@Override
public String getPrefix(ConversationContext context) {
public @NonNull String getPrefix(ConversationContext context) {
User user = User.getInstance((Player)context.getForWhom());
return user.getTranslation("commands.admin.blueprint.management.name.conversation-prefix");
}

View File

@ -38,7 +38,7 @@ public class NamePrompt extends StringPrompt {
}
@Override
public String getPromptText(ConversationContext context) {
public @NonNull String getPromptText(ConversationContext context) {
User user = User.getInstance((Player)context.getForWhom());
return user.getTranslation("commands.admin.blueprint.management.name.prompt");
}

View File

@ -34,7 +34,7 @@ public class NameSuccessPrompt extends MessagePrompt {
}
@Override
public String getPromptText(ConversationContext context) {
public @NonNull String getPromptText(ConversationContext context) {
String name = (String) context.getSessionData("name");
String uniqueId = (String) context.getSessionData("uniqueId");
User user = User.getInstance((Player)context.getForWhom());
@ -65,7 +65,7 @@ public class NameSuccessPrompt extends MessagePrompt {
}
@Override
protected Prompt getNextPrompt(ConversationContext context) {
protected Prompt getNextPrompt(@NonNull ConversationContext context) {
return Prompt.END_OF_CONVERSATION;
}

Some files were not shown because too many files have changed in this diff Show More