mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
Merge branch 'commands-on-island-creation' into develop
This commit is contained in:
commit
93219cbc1c
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
@ -76,6 +77,17 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
||||
// Remove them from this island (it still exists and will be deleted later)
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
if (target.isOnline()) {
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", target.getName());
|
||||
if (command.startsWith("[SUDO]")) {
|
||||
// Execute the command by the player
|
||||
target.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
target.getPlayer().getEnderChest().clear();
|
||||
|
@ -165,6 +165,18 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
// Remove player
|
||||
getIslands().removePlayer(getWorld(), memberUUID);
|
||||
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(island.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", member.getName());
|
||||
if (command.startsWith("[SUDO]") && member.isOnline()) {
|
||||
// Execute the command by the player
|
||||
member.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
if (member.isOnline()) {
|
||||
|
@ -78,6 +78,17 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
target.sendMessage("commands.island.team.kick.owner-kicked", "[gamemode]", getAddon().getDescription().getName());
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(oldIsland.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", target.getName());
|
||||
if (command.startsWith("[SUDO]") && target.isOnline()) {
|
||||
// Execute the command by the player
|
||||
target.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
if (target.isOnline()) {
|
||||
|
@ -72,6 +72,17 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(island.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", user.getName());
|
||||
if (command.startsWith("[SUDO]") && user.isOnline()) {
|
||||
// Execute the command by the player
|
||||
user.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
|
||||
/**
|
||||
@ -186,6 +187,27 @@ public interface WorldSettings extends ConfigObject {
|
||||
*/
|
||||
boolean isOnJoinResetMoney();
|
||||
|
||||
/**
|
||||
* Returns a list of commands that should be executed when the player joins an island or creates one.<br/>
|
||||
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
|
||||
* <br/>
|
||||
* Available placeholders for the commands are the following:
|
||||
* <ul>
|
||||
* <li>{@code [player]}: name of the player</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Here are some examples of valid commands to execute:
|
||||
* <ul>
|
||||
* <li>{@code "[SUDO] bbox version"}</li>
|
||||
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
|
||||
* </ul>
|
||||
* @return a list of commands.
|
||||
* @since 1.8.0
|
||||
* @see #getOnLeaveCommands()
|
||||
*/
|
||||
@NonNull
|
||||
List<String> getOnJoinCommands();
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetEnderChest
|
||||
*/
|
||||
@ -201,6 +223,29 @@ public interface WorldSettings extends ConfigObject {
|
||||
*/
|
||||
boolean isOnLeaveResetMoney();
|
||||
|
||||
/**
|
||||
* Returns a list of commands that should be executed when the player leaves an island or resets one.<br/>
|
||||
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
|
||||
* <br/>
|
||||
* Available placeholders for the commands are the following:
|
||||
* <ul>
|
||||
* <li>{@code [player]}: name of the player</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Here are some examples of valid commands to execute:
|
||||
* <ul>
|
||||
* <li>{@code "[SUDO] bbox version"}</li>
|
||||
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Note that player-executed commands might not work, as these commands can be run with said player being offline.
|
||||
* @return a list of commands.
|
||||
* @since 1.8.0
|
||||
* @see #getOnJoinCommands()
|
||||
*/
|
||||
@NonNull
|
||||
List<String> getOnLeaveCommands();
|
||||
|
||||
/**
|
||||
* @return true if the default world generator should not operate in this world
|
||||
*/
|
||||
|
@ -562,6 +562,18 @@ public class IslandWorldManager {
|
||||
return gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of commands to execute when the player creates or joins an island.
|
||||
* @param world the World
|
||||
* @return a list of commands
|
||||
* @since 1.8.0
|
||||
* @see #getOnLeaveCommands(World)
|
||||
*/
|
||||
@NonNull
|
||||
public List<String> getOnJoinCommands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getOnJoinCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetMoney
|
||||
*/
|
||||
@ -583,6 +595,18 @@ public class IslandWorldManager {
|
||||
return gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of commands to execute when the player resets or leaves an island.
|
||||
* @param world the World
|
||||
* @return a list of commands
|
||||
* @since 1.8.0
|
||||
* @see #getOnJoinCommands(World)
|
||||
*/
|
||||
@NonNull
|
||||
public List<String> getOnLeaveCommands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getOnLeaveCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data folder for the addon that registered this world
|
||||
*
|
||||
|
@ -670,7 +670,17 @@ public class IslandsManager {
|
||||
}
|
||||
// If this is a new island, then run commands and do resets
|
||||
if (newIsland) {
|
||||
// TODO add command running
|
||||
// Execute commands
|
||||
plugin.getIWM().getOnJoinCommands(world).forEach(command -> {
|
||||
command = command.replace("[player]", player.getName());
|
||||
if (command.startsWith("[SUDO]")) {
|
||||
// Execute the command by the player
|
||||
player.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove money inventory etc.
|
||||
if (plugin.getIWM().isOnJoinResetEnderChest(world)) {
|
||||
|
Loading…
Reference in New Issue
Block a user