Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions API/src/main/java/dev/lrxh/api/arena/IArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public interface IArena {
void delete(boolean save);

boolean equals(Object o);

long getTime();
}
19 changes: 11 additions & 8 deletions Plugin/src/main/java/dev/lrxh/neptune/game/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.lrxh.blockChanger.snapshot.CuboidSnapshot;
import dev.lrxh.neptune.Neptune;
import dev.lrxh.neptune.game.kit.KitService;
import dev.lrxh.neptune.utils.tasks.NeptuneRunnable;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.*;
Expand Down Expand Up @@ -34,18 +33,20 @@ public class Arena implements IArena {
private Location min;
private Location max;
private double buildLimit;
private long time;
private List<Material> whitelistedBlocks;
private CuboidSnapshot snapshot;
private Arena owner;
private boolean doneLoading;

public Arena(String name, String displayName, Location redSpawn, Location blueSpawn, boolean enabled, int deathY) {
public Arena(String name, String displayName, Location redSpawn, Location blueSpawn, boolean enabled, int deathY, long time) {
this.name = name;
this.displayName = displayName;
this.redSpawn = redSpawn;
this.blueSpawn = blueSpawn;
this.enabled = enabled;
this.deathY = deathY;
this.time = time;

this.buildLimit = 0;
this.whitelistedBlocks = new ArrayList<>();
Expand All @@ -54,9 +55,9 @@ public Arena(String name, String displayName, Location redSpawn, Location blueSp

public Arena(String name, String displayName, Location redSpawn, Location blueSpawn,
Location min, Location max, double buildLimit, boolean enabled,
List<Material> whitelistedBlocks, int deathY) {
List<Material> whitelistedBlocks, int deathY, long time) {

this(name, displayName, redSpawn, blueSpawn, enabled, deathY);
this(name, displayName, redSpawn, blueSpawn, enabled, deathY, time);
this.min = min;
this.max = max;
this.buildLimit = buildLimit;
Expand All @@ -74,16 +75,16 @@ public Arena(String name, String displayName, Location redSpawn, Location blueSp

public Arena(String name, String displayName, Location redSpawn, Location blueSpawn,
Location min, Location max, double buildLimit, boolean enabled,
List<Material> whitelistedBlocks, int deathY, CuboidSnapshot snapshot, Arena owner) {
List<Material> whitelistedBlocks, int deathY, long time, CuboidSnapshot snapshot, Arena owner) {

this(name, displayName, redSpawn, blueSpawn, min, max, buildLimit, enabled, whitelistedBlocks, deathY);
this(name, displayName, redSpawn, blueSpawn, min, max, buildLimit, enabled, whitelistedBlocks, deathY, time);
this.snapshot = snapshot;
this.owner = owner;
this.doneLoading = (snapshot != null);
}

public Arena(String name) {
this(name, name, null, null, false, -68321);
public Arena(String name, long time) {
this(name, name, null, null, false, -68321, time);
this.min = null;
this.max = null;
this.buildLimit = 68321;
Expand Down Expand Up @@ -168,6 +169,7 @@ public boolean shouldGenerateStructures(@NotNull WorldInfo worldInfo, @NotNull R
world.setGameRule(GameRules.SHOW_ADVANCEMENT_MESSAGES, false);
world.setGameRule(GameRules.IMMEDIATE_RESPAWN, true);
world.setDifficulty(Difficulty.HARD);
world.setTime(time);
});

Location min = this.min.clone();
Expand Down Expand Up @@ -195,6 +197,7 @@ public boolean shouldGenerateStructures(@NotNull WorldInfo worldInfo, @NotNull R
this.enabled,
new ArrayList<>(this.whitelistedBlocks),
this.deathY,
this.time,
this,
virtualWorld
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Arena loadArena(String arenaName) {
Location blueSpawn = LocationUtil.deserialize(config.getString(path + "blueSpawn"));
boolean enabled = config.getBoolean(path + "enabled");
int deathY = config.getInt(path + "deathY", -68321);

long time = config.contains(path + "time") ? config.getLong(path + "time") : 0;

Location edge1 = LocationUtil.deserialize(config.getString(path + "min"));
Location edge2 = LocationUtil.deserialize(config.getString(path + "max"));
Expand All @@ -66,7 +66,7 @@ public Arena loadArena(String arenaName) {
whitelistedBlocks.add(Material.getMaterial(name));
}

return new Arena(arenaName, displayName, redSpawn, blueSpawn, edge1, edge2, limit, enabled, whitelistedBlocks, deathY);
return new Arena(arenaName, displayName, redSpawn, blueSpawn, edge1, edge2, limit, enabled, whitelistedBlocks, deathY, time);
}


Expand All @@ -84,6 +84,7 @@ public void save() {
new Value("blueSpawn", LocationUtil.serialize(arena.getBlueSpawn())),
new Value("enabled", arena.isEnabled()),
new Value("deathY", arena.getDeathY()),
new Value("time", arena.getTime()),
new Value("limit", arena.getBuildLimit()),
new Value("whitelistedBlocks", arena.getWhitelistedBlocksAsString())
));
Expand All @@ -110,7 +111,7 @@ public Arena getArenaByName(String arenaName) {
}

public Arena copyFrom(IArena arena) {
return new Arena(arena.getName(), arena.getDisplayName(), arena.getRedSpawn(), arena.getBlueSpawn(), arena.getMin(), arena.getMax(), arena.getBuildLimit(), arena.isEnabled(), arena.getWhitelistedBlocks(), arena.getDeathY());
return new Arena(arena.getName(), arena.getDisplayName(), arena.getRedSpawn(), arena.getBlueSpawn(), arena.getMin(), arena.getMax(), arena.getBuildLimit(), arena.isEnabled(), arena.getWhitelistedBlocks(), arena.getDeathY(), arena.getTime());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class VirtualArena implements IArena {
private final String displayName;
private final boolean enabled;
private final int deathY;
private final long time;
private final double buildLimit;
private final List<Material> whitelistedBlocks;
private final IArena owner;
Expand All @@ -39,6 +40,7 @@ public VirtualArena(String name,
boolean enabled,
List<Material> whitelistedBlocks,
int deathY,
long time,
IArena owner,
VirtualWorld virtualWorld) {
this.name = name;
Expand All @@ -51,6 +53,7 @@ public VirtualArena(String name,
this.enabled = enabled;
this.whitelistedBlocks = whitelistedBlocks;
this.deathY = deathY;
this.time = time;
this.owner = owner;
this.virtualWorld = virtualWorld;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public List<Button> getButtons(Player player) {
buttons.add(new ArenaDeleteButton(21, arena));

buttons.add(new ArenaSetDeathYButton(9, arena));

buttons.add(new ArenaSetTimeButton(10, arena));

buttons.add(new ArenaSetLimitButton(4, arena));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.lrxh.neptune.game.arena.menu.button;

import dev.lrxh.neptune.API;
import dev.lrxh.neptune.game.arena.Arena;
import dev.lrxh.neptune.game.arena.procedure.ArenaProcedureType;
import dev.lrxh.neptune.profile.impl.Profile;
import dev.lrxh.neptune.utils.CC;
import dev.lrxh.neptune.utils.ItemBuilder;
import dev.lrxh.neptune.utils.menu.Button;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;


public class ArenaSetTimeButton extends Button {
private final Arena arena;

public ArenaSetTimeButton(int slot, Arena arena) {
super(slot, false);
this.arena = arena;
}

@Override
public void onClick(ClickType type, Player player) {
Profile profile = API.getProfile(player);
profile.getArenaProcedure().setArena(arena);
profile.getArenaProcedure().setType(ArenaProcedureType.SET_TIME);
player.sendMessage(CC.info("Type the time (in ticks or day, night, ...) for the arena. Type &8Current &7to use the current world time"));

player.closeInventory();
}

@Override
public ItemStack getItemStack(Player player) {
return new ItemBuilder(Material.GOLD_INGOT).name("&cSet Arena Time").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public void onChat(AsyncChatEvent event) {
return;
}


Arena arena = new Arena(input);
Arena arena = new Arena(input, player.getWorld().getTime());

ArenaService.get().arenas.add(arena);
player.sendMessage(CC.success("Created arena"));
Expand Down Expand Up @@ -184,6 +183,32 @@ public void run() {
new WhitelistedBlocksMenu(arena).open(player);
profile.getArenaProcedure().setArena(null);
}
case SET_TIME -> {
event.setCancelled(true);

profile.getArenaProcedure().setType(ArenaProcedureType.NONE);
Arena arena = profile.getArenaProcedure().getArena();
if (input.equalsIgnoreCase("day")) arena.setTime(1000);
if (input.equalsIgnoreCase("night")) arena.setTime(13000);
else if (input.equalsIgnoreCase("noon")) arena.setTime(6000);
else if (input.equalsIgnoreCase("midnight")) arena.setTime(18000);
else if (input.equalsIgnoreCase("sunrise")) arena.setTime(23000);
else if (input.equalsIgnoreCase("sunset")) arena.setTime(12000);
else if (input.equalsIgnoreCase("current")) arena.setTime(player.getWorld().getTime());
else {
try {
long time = Long.parseLong(input);
arena.setTime(time);
} catch (NumberFormatException e) {
player.sendMessage(CC.error("Invalid time input"));
return;
}
}
player.sendMessage(CC.success("Set arena time"));
new ArenaManagementMenu(arena).open(player);
profile.getArenaProcedure().setArena(null);
}
default -> {}
}

ArenaService.get().save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public enum ArenaProcedureType {
SET_SPAWN_MIN,
SET_BUILD_LIMIT,
SET_DEATH_Y,
ADD_BLOCK
ADD_BLOCK,
SET_TIME
}