Skip to content

Commit

Permalink
Merge pull request #2564 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
tastybento authored Nov 26, 2024
2 parents d29eb88 + 55daa72 commit 2dd736a
Show file tree
Hide file tree
Showing 66 changed files with 1,492 additions and 619 deletions.
10 changes: 3 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@
</issueManagement>

<distributionManagement>
<snapshotRepository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.org/repository/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>codemc-releases</id>
<url>https://repo.codemc.org/repository/maven-releases</url>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
</repository>
</distributionManagement>

Expand Down Expand Up @@ -88,7 +84,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.7.0</build.version>
<build.version>3.0.1</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package world.bentobox.bentobox;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -464,6 +466,32 @@ public boolean loadSettings() {
getPluginLoader().disablePlugin(this);
return false;
}
log("Saving default panels...");

if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "island_creation_panel.yml"))) {
log("Saving default island_creation_panel...");
this.saveResource("panels/island_creation_panel.yml", false);
}

if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "language_panel.yml"))) {
log("Saving default language_panel...");
this.saveResource("panels/language_panel.yml", false);
}

if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "island_homes_panel.yml"))) {
log("Saving default island_homes_panel...");
this.saveResource("panels/island_homes_panel.yml", false);
}

if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "team_invite_panel.yml"))) {
log("Saving default team_invite_panel...");
this.saveResource("panels/team_invite_panel.yml", false);
}

if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "team_panel.yml"))) {
log("Saving default team_panel...");
this.saveResource("panels/team_panel.yml", false);
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.api.logs.LogEntry.LogType;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
Expand Down Expand Up @@ -115,10 +116,10 @@ void unregisterIsland(User user) {
// Remove all island players that reference this island
targetIsland.getMembers().clear();
if (user.isPlayer()) {
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
targetIsland.log(new LogEntry.Builder(LogType.UNREGISTER).data("player", targetUUID.toString())
.data("admin", user.getUniqueId().toString()).build());
} else {
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
targetIsland.log(new LogEntry.Builder(LogType.UNREGISTER).data("player", targetUUID.toString())
.data("admin", "console").build());
}
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.IslandInfo;
import world.bentobox.bentobox.util.Util;

/**
Expand Down Expand Up @@ -59,35 +58,28 @@ public boolean canExecute(User user, String label, List<String> args) {

@Override
public boolean execute(User user, String label, @NonNull List<String> args) {
Island island = getIslands().getIsland(getWorld(), targetUUID);
if (island == null) {
List<Island> islands = getIslands().getIslands(getWorld(), targetUUID);
if (islands.isEmpty()) {
return false;
}
if (targetUUID.equals(island.getOwner())) {
user.sendMessage("commands.admin.team.kick.cannot-kick-owner");
new IslandInfo(island).showMembers(user);
return false;
}
User target = User.getInstance(targetUUID);
target.sendMessage("commands.admin.team.kick.admin-kicked");
islands.forEach(island -> {
if (!user.getUniqueId().equals(island.getOwner())) {
User target = User.getInstance(targetUUID);
target.sendMessage("commands.admin.team.kick.admin-kicked");

getIslands().removePlayer(island, targetUUID);
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
getIslands().removePlayer(island, targetUUID);
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]",
getPlayers().getName(island.getOwner()));
// Fire event so add-ons know
TeamEvent.builder().island(island).reason(TeamEvent.Reason.KICK).involvedPlayer(targetUUID).admin(true)
.build();
IslandEvent.builder().island(island).involvedPlayer(targetUUID).admin(true)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(target), RanksManager.VISITOR_RANK).build();
}
});
user.sendMessage("commands.admin.team.kick.success-all");

// Fire event so add-ons know
TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.admin(true)
.build();
IslandEvent.builder()
.island(island)
.involvedPlayer(targetUUID)
.admin(true)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(target), RanksManager.VISITOR_RANK)
.build();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public boolean canExecute(User user, String label, List<String> args) {
// Check number of homes

int maxHomes = getIslands().getMaxHomes(island);
if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes) {
// The + 1 is for the default home
if (getIslands().getNumberOfHomesIfAdded(island, String.join(" ", args)) > maxHomes + 1) {
user.sendMessage("commands.island.sethome.too-many-homes", TextVariables.NUMBER, String.valueOf(maxHomes));
user.sendMessage("commands.island.sethome.homes-are");
getIslands().getIslands(getWorld(), user).forEach(is ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.api.logs.LogEntry.LogType;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
Expand Down Expand Up @@ -120,6 +122,9 @@ void acceptTrustInvite(User user, TeamInvite invite) {
user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName(),
TextVariables.DISPLAY_NAME, inviter.getDisplayName());
}
// Add historu record
island.log(new LogEntry.Builder(LogType.TRUSTED).data(user.getUniqueId().toString(), "trusted")
.data(invite.getInviter().toString(), "trusted by").build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.api.logs.LogEntry.LogType;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
Expand Down Expand Up @@ -91,6 +93,9 @@ protected boolean setOwner(User user, @NonNull UUID targetUUID2) {
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK)
.build();
// Add historu record
island.log(new LogEntry.Builder(LogType.NEWOWNER).data(targetUUID2.toString(), "new owner")
.data(user.getUniqueId().toString(), "old owner").build());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.api.logs.LogEntry.LogType;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
Expand Down Expand Up @@ -110,6 +112,10 @@ public boolean execute(User user, String label, List<String> args) {
island.setRank(target, RanksManager.TRUSTED_RANK);
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName());
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
// Add historu record
island.log(new LogEntry.Builder(LogType.TRUSTED).data(targetUUID.toString(), "trusted")
.data(user.getUniqueId().toString(), "trusted by").build());

}
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;
import java.util.logging.Logger;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.BentoBox;
Expand Down Expand Up @@ -64,9 +63,9 @@ public T loadConfigObject(String uniqueId) {
return handler.loadObject(uniqueId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load config object! " + e.getMessage());
BentoBox.getInstance().logError("Could not load config object! " + e.getMessage());
// Required for debugging
logger.severe(ExceptionUtils.getStackTrace(e));
e.printStackTrace();
}

return null;
Expand Down
107 changes: 100 additions & 7 deletions src/main/java/world/bentobox/bentobox/api/logs/LogEntry.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package world.bentobox.bentobox.api.logs;

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNull;
Expand All @@ -15,28 +14,110 @@
* An {@link world.bentobox.bentobox.database.objects.adapters.AdapterInterface AdapterInterface} is provided to be able to save/retrieve
* a list of instances of this object to/from the database: {@link world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter LogEntryListAdapter}.
*
* @author Poslovitch
* @author Poslovitch, tastybento
*
*/
public class LogEntry {
@Expose
private final long timestamp;
@Expose
private final String type;
private final LogType type;
@Expose
private final String customType;
@Expose
private final Map<String, String> data;

/**
* This is a log enum. If you are a developer and need more make a PR. Or use the string one.
*/
public enum LogType {
/**
* Something removed
*/
REMOVE,
/**
* Something added
*/
ADD,
/**
* Island unregistered
*/
UNREGISTER,
/**
* Player banned
*/
BAN,
/**
* Something was completed
*/
COMPELTE,
/**
* Island became unowned
*/
UNOWNED,
/**
* Island became spawn
*/
SPAWN,
/**
* Player unbanned
*/
UNBAN,
/**
* Player joined
*/
JOINED,
/**
* New owner made
*/
NEWOWNER,
/**
* Player trusted
*/
TRUSTED,
/**
* Player cooped
*/
COOP,
/**
* Unknown reason
*/
UNKNOWN,
/**
* Island reset or a reset of some kind
*/
RESET,
/**
* Everything was reset
*/
RESET_ALL,
/**
* New thing
*/
NEW,
/**
* Something duplicated
*/
DUPLICATE,
/**
* General info
*/
INFO,
}

private LogEntry(@NonNull Builder builder) {
this.timestamp = builder.timestamp;
this.type = builder.type;
this.data = builder.data;
this.customType = builder.customType;
}

public long getTimestamp() {
return timestamp;
}

@NonNull
public String getType() {
public LogType getType() {
return type;
}

Expand All @@ -47,13 +128,25 @@ public Map<String, String> getData() {

public static class Builder {
private long timestamp;
private final String type;
private final LogType type;
private Map<String, String> data;
private final String customType;

public Builder(@NonNull String type) {
public Builder(LogType type) {
this.timestamp = System.currentTimeMillis();
this.type = type;
this.data = new LinkedHashMap<>();
this.customType = null;
}

/**
* @param customType log type
*/
public Builder(String customType) {
this.timestamp = System.currentTimeMillis();
this.type = type.toUpperCase(Locale.ENGLISH);
this.type = LogType.UNKNOWN;
this.data = new LinkedHashMap<>();
this.customType = customType;
}

public Builder timestamp(long timestamp) {
Expand Down
Loading

0 comments on commit 2dd736a

Please sign in to comment.