Skip to content

Commit

Permalink
Merge pull request #316 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.13.0
  • Loading branch information
tastybento authored Apr 16, 2023
2 parents 3976383 + 86ae5d1 commit a7e1318
Show file tree
Hide file tree
Showing 16 changed files with 627 additions and 138 deletions.
13 changes: 3 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.21.0</bentobox.version>
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.22.0</bentobox.version>
<level.version>2.6.2</level.version>
<bank.version>1.3.0</bank.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- 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.12.3</build.version>
<build.version>1.13.0</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -157,13 +157,6 @@
<version>1.2.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Holographic Displays API -->
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
<!-- Apache Commons Text -->
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
46 changes: 8 additions & 38 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
import java.io.IOException;
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;

import world.bentobox.aoneblock.commands.admin.AdminCommand;
import world.bentobox.aoneblock.commands.island.PlayerCommand;
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
Expand All @@ -30,7 +24,6 @@
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
import world.bentobox.aoneblock.requests.IslandStatsHandler;
import world.bentobox.aoneblock.requests.LocationStatsHandler;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings;
Expand All @@ -53,7 +46,6 @@ public class AOneBlock extends GameModeAddon {
private BlockListener blockListener;
private OneBlocksManager oneBlockManager;
private PlaceholdersManager phManager;
private boolean useHolographicDisplays;
private HoloListener holoListener;

@Override
Expand Down Expand Up @@ -109,12 +101,9 @@ public void onEnable() {
registerRequestHandler(new IslandStatsHandler(this));
registerRequestHandler(new LocationStatsHandler(this));

// Decide if HolographicDisplays is Usable
useHolographicDisplays = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
if (this.useHolographicDisplays) {
holoListener = new HoloListener(this);
registerListener(holoListener);
}
// Register Holograms
holoListener = new HoloListener(this);
registerListener(holoListener);
}

private void registerPlaceholders() {
Expand All @@ -140,6 +129,9 @@ private void registerPlaceholders() {
public void onDisable() {
// save cache
blockListener.saveCache();

// Clear holograms
holoListener.clear();
}

@Override
Expand Down Expand Up @@ -263,21 +255,7 @@ public void allLoaded() {
this.saveWorldSettings();

// Manage Old Holograms
if (useHolographicDisplays()) {
getIslands().getIslands().stream()
.filter(i -> this.inWorld(i.getWorld()))
.forEach(island -> {
OneBlockIslands oneBlockIsland = getOneBlocksIsland(island);
String hololine = oneBlockIsland.getHologram();
Location center = island.getCenter();
if (!hololine.isEmpty()) {
final Hologram hologram = HologramsAPI.createHologram(BentoBox.getInstance(), center.add(0.5, 2.6, 0.5));
for (String line : hololine.split("\\n")) {
hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line));
}
}
});
}
holoListener.setUp();
}

/**
Expand Down Expand Up @@ -315,12 +293,4 @@ public PlaceholdersManager getPlaceholdersManager() {
public HoloListener getHoloListener() {
return holoListener;
}

/**
* @return whether to use Holographic Displays or Not
*/
public boolean useHolographicDisplays() {
return useHolographicDisplays;
}

}
8 changes: 0 additions & 8 deletions src/main/java/world/bentobox/aoneblock/AOneBlockPladdon.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package world.bentobox.aoneblock;

import org.bukkit.plugin.java.annotation.dependency.Dependency;
import org.bukkit.plugin.java.annotation.plugin.ApiVersion;
import org.bukkit.plugin.java.annotation.plugin.Plugin;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.Pladdon;


@Plugin(name="Pladdon", version="1.0")
@ApiVersion(ApiVersion.Target.v1_17)
@Dependency(value = "BentoBox")
public class AOneBlockPladdon extends Pladdon {

@Override
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "aoneblock.command.set-count-command", since = "1.10.0")
private String setCountCommand = "setCount";

@ConfigComment("How long a player must wait until they can use the setCount command again. In minutes.")
@ConfigComment("This is the command that is run from the phases panel.")
@ConfigEntry(path = "aoneblock.command.set-count-cooldown", since = "1.13.0")
private int setCountCooldown = 5;

@ConfigComment("The command label that allows to check if magic block is present and respawns it if not.")
@ConfigComment("By default it is 'respawnBlock check'.")
@ConfigEntry(path = "aoneblock.command.respawn-block-command", since = "1.10.0")
Expand All @@ -96,6 +101,10 @@ public class Settings implements WorldSettings {
@ConfigComment("Other plugins may override this setting")
@ConfigEntry(path = "world.difficulty")
private Difficulty difficulty = Difficulty.NORMAL;

@ConfigComment("Display holograms")
@ConfigEntry(path = "world.holograms")
private boolean useHolograms = true;

@ConfigComment("Duration in seconds that phase holograms will exist after being displayed, if used.")
@ConfigComment("If set to 0, then holograms will persist until cleared some other way.")
Expand Down Expand Up @@ -2004,4 +2013,32 @@ public int getHologramDuration() {
public void setHologramDuration(int hologramDuration) {
this.hologramDuration = hologramDuration;
}

/**
* @return the setCountCooldown
*/
public int getSetCountCooldown() {
return setCountCooldown;
}

/**
* @param setCountCooldown the setCountCooldown to set
*/
public void setSetCountCooldown(int setCountCooldown) {
this.setCountCooldown = setCountCooldown;
}

/**
* @return the useHolograms
*/
public boolean isUseHolograms() {
return useHolograms;
}

/**
* @param useHolograms the useHolograms to set
*/
public void setUseHolograms(boolean useHolograms) {
this.useHolograms = useHolograms;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package world.bentobox.aoneblock.commands.island;

import java.util.List;
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNull;

Expand Down Expand Up @@ -35,6 +36,16 @@ public void setup() {
// Permission
setPermission("island.setcount");
addon = getAddon();
setConfigurableRankCommand();
}

@Override
public boolean canExecute(User user, String label, List<String> args) {
// Check cooldown
if (addon.getSettings().getSetCountCooldown() > 0 && checkCooldown(user)) {
return false;
}
return true;
}

@Override
Expand All @@ -43,15 +54,16 @@ public boolean execute(User user, String label, List<String> args) {
showHelp(this, user);
return false;
}
// Get their island
Island island = getIslands().getIsland(getWorld(), user);
if (island == null) {
// Player issuing the command must have an island or be in a team
if (!getIslands().inTeam(getWorld(), user.getUniqueId()) && !getIslands().hasIsland(getWorld(), user.getUniqueId())) {
user.sendMessage("general.errors.no-island");
return false;
}
// Check ownership
if (!getIslands().hasIsland(getWorld(), user)) {
user.sendMessage("general.errors.not-owner");
// Check rank to use command
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;
}
// Get value
Expand All @@ -72,6 +84,7 @@ public boolean execute(User user, String label, List<String> args) {
i.setBlockNumber(count);
i.clearQueue();
user.sendMessage("aoneblock.commands.island.setcount.set", TextVariables.NUMBER, String.valueOf(i.getBlockNumber()));
setCooldown(user.getUniqueId(), addon.getSettings().getSetCountCooldown() * 60);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ private void setUp(@NonNull Island island) {
OneBlockIslands is = new OneBlockIslands(island.getUniqueId());
cache.put(island.getUniqueId(), is);
handler.saveObjectAsync(is);
if (addon.useHolographicDisplays()) {
addon.getHoloListener().setUp(island, is);
}
addon.getHoloListener().setUp(island, is, true);
}


Expand Down Expand Up @@ -389,9 +387,7 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player
}
}
// Manage Holograms
if (addon.useHolographicDisplays()) {
addon.getHoloListener().process(i, is, phase);
}
addon.getHoloListener().process(i, is, phase);
// Play warning sound for upcoming mobs
if (addon.getSettings().getMobWarning() > 0) {
playWarning(is, block);
Expand Down Expand Up @@ -505,7 +501,7 @@ private void playWarning(@NonNull OneBlockIslands is, @NonNull Block block) {
* @param phase - current phase name
* @return true if this is a new phase, false if not
*/
private boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) {
protected boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) {
// Handle NPCs
User user;
if (player == null || player.hasMetadata("NPC")) {
Expand All @@ -523,6 +519,12 @@ private boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull
Util.runCommands(user,
replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()),
"Commands run for end of " + oldPhaseName);
// If first time
if (is.getBlockNumber() >= is.getLifetime()) {
Util.runCommands(user,
replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getFirstTimeEndCommands()),
"Commands run for first time completing " + oldPhaseName);
}
});
// Set the phase name
is.setPhaseName(phaseName);
Expand Down
Loading

0 comments on commit a7e1318

Please sign in to comment.