Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more things of GenTiers accessible to fix compatibility with Pri… #26

Merged
merged 1 commit into from
Feb 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,40 @@ public static void loadTweaksConfigs(MBedwarsTweaksPlugin plugin) {
public static HashMap<Integer, GenTierLevel> getDefaultGenTiers() {
return new HashMap<Integer, GenTierLevel>() {{
put(1, new GenTierLevel(
1,
"Diamond II", "&eTier &cII",
"diamond",
TierAction.GEN_UPGRADE, 6, 30D, null,
"&bDiamond Generators &ehave been upgraded to Tier &4II",
null
));
put(2, new GenTierLevel(
2,
"Emerald II", "&eTier &cII",
"emerald",
TierAction.GEN_UPGRADE, 6, 40D, null,
"&aEmerald Generators &ehave been upgraded to Tier &4II",
null
));
put(3, new GenTierLevel(
3,
"Diamond III", "&eTier &cIII",
"diamond",
TierAction.GEN_UPGRADE, 6, 20D, null,
"&bDiamond Generators &ehave been upgraded to Tier &4III",
null
));
put(4, new GenTierLevel(
4,
"Emerald III", "&eTier &cIII",
"emerald",
TierAction.GEN_UPGRADE, 6, 30D, null,
"&aEmerald Generators &ehave been upgraded to Tier &4III",
null
));
put(5, new GenTierLevel("Bed Destroy", TierAction.BED_DESTROY, 5, null, null));
put(6, new GenTierLevel("Sudden Death", TierAction.SUDDEN_DEATH, 10, null, null));
put(7, new GenTierLevel("Game Over", TierAction.GAME_OVER, 10, null, null));
put(5, new GenTierLevel(5, "Bed Destroy", TierAction.BED_DESTROY, 5, null, null));
put(6, new GenTierLevel(6, "Sudden Death", TierAction.SUDDEN_DEATH, 10, null, null));
put(7, new GenTierLevel(7, "Game Over", TierAction.GAME_OVER, 10, null, null));
}};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private static void loadUnchecked() throws Exception {
if (action == TierAction.GEN_UPGRADE) {

final GenTierLevel genTierLevel = new GenTierLevel(
levelNum,
tierName,
tierLevel,
typeString,
Expand All @@ -118,6 +119,7 @@ private static void loadUnchecked() throws Exception {
} else {

final GenTierLevel genTierLevel = new GenTierLevel(
levelNum,
tierName,
action,
time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,51 @@
import de.marcely.bedwars.api.arena.Arena;
import de.marcely.bedwars.api.game.spawner.DropType;
import de.marcely.bedwars.api.message.Message;
import lombok.Getter;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

@Getter
@Data
@AllArgsConstructor
public class GenTierLevel {

private final String tierName;
private final TierAction action;
private final double time;
private final int tier;
private final String tierName; // Display Name
@Nullable
private final String holoName;
private final String holoName; // Example '&eTier &cII'
@Nullable
private final String typeId;
private final String typeId; // Spawners with this drop-type should update
private final TierAction action; // Action (eg bed break or upgrade)
private final double time; // Time until the update happens (After Last Event)
@Nullable
private final Double speed;
private final Double speed; // New drop speed
@Nullable
private final Integer limit;
private final Integer limit; // New drop speed
@Nullable
private final String earnMessage;
private final String earnMessage; // The chat message displayed on update
@Nullable
private final Sound earnSound;
private final Sound earnSound; // Sound played when a tier is earned

public GenTierLevel(
int tier,
String tierName,
TierAction action,
double time,
@Nullable String earnMessage,
@Nullable Sound earnSound
) {
this.tierName = tierName;
this.holoName = null;
this.typeId = null;
this.action = action;
this.time = time;
this.speed = null;
this.limit = null;
this.earnMessage = earnMessage;
this.earnSound = earnSound;
}
@Nullable Sound earnSound) {

public GenTierLevel(
String tierName, // Display Name
@Nullable String holoName, // Example '&eTier &cII'
@Nullable String typeId, // Spawners with this drop-type should update
TierAction action, // Action (eg bed break or upgrade)
double time, // Time until the update happens (After Last Event)
@Nullable Double speed, // New drop speed
@Nullable Integer limit, // New drop speed
@Nullable String earnMessage, // The chat message displayed on update
@Nullable Sound earnSound // Sound played when a tier is earned
) {
this.tierName = tierName;
this.holoName = holoName;
this.typeId = typeId;
this.action = action;
this.time = time;
this.speed = speed;
this.limit = limit;
this.earnMessage = earnMessage;
this.earnSound = earnSound;
this(tier,
tierName,
null,
null,
action,
time,
null,
null,
earnMessage,
earnSound);
}

public void broadcastEarn(Arena arena, boolean messageSupported) {
Expand All @@ -76,10 +59,10 @@ public void broadcastEarn(Arena arena, boolean messageSupported) {

if (messageSupported && this.earnMessage != null)
arena.broadcast(Message.build(this.earnMessage));

}

public DropType getType() {
public @Nullable DropType getType() {
return GameAPI.get().getDropTypeById(this.typeId);
}
}
49 changes: 30 additions & 19 deletions src/main/java/me/metallicgoat/tweaksaddon/gentiers/GenTiers.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public class GenTiers implements Listener {

private static final Map<Arena, GenTierState> arenaStates = new IdentityHashMap<>();

public static @Nullable GenTierState getState(Arena arena) {
return arenaStates.get(arena);
}

@EventHandler
public void onRoundStartEvent(RoundStartEvent event) {
if (!MainConfig.gen_tiers_enabled)
Expand Down Expand Up @@ -64,44 +60,58 @@ public void onArenaDeleteEvent(ArenaDeleteEvent event) {
removeArena(event.getArena());
}

private void removeArena(Arena arena) {
public static @Nullable GenTierState getState(Arena arena) {
return arenaStates.get(arena);
}

// Accessed by PrivateGamesAddon
public static void removeArena(Arena arena) {
final GenTierState state = arenaStates.remove(arena);

cancelTask(state);
if (state != null)
cancelTask(state);
}

private void cancelTask(GenTierState state) {
private static void cancelTask(GenTierState state) {
if (state != null && state.genTierTask != null)
state.genTierTask.cancel();
}

private void scheduleNextTier(Arena arena, int tier) {
final GenTierLevel currentLevel = GenTiersConfig.gen_tier_levels.get(tier);
// Accessed by PrivateGamesAddon
public static void scheduleNextTier(Arena arena, GenTierLevel level, double time) {
final GenTierState state = getState(arena);

// Check if tier exists
if (currentLevel == null || state == null)
if (state == null)
return;

state.nextTierName = currentLevel.getTierName();
state.nextUpdateTime = System.currentTimeMillis() + (long) (currentLevel.getTime() * 60 * 1000);
state.nextTierName = level.getTierName();
state.nextUpdateTime = System.currentTimeMillis() + (long) (time * 60 * 1000);

cancelTask(state); // Cancel existing tasks

if (currentLevel.getAction() == TierAction.GAME_OVER) {
arena.setIngameTimeRemaining((int) (currentLevel.getTime() * 60));
if (level.getAction() == TierAction.GAME_OVER) {
arena.setIngameTimeRemaining((int) (time * 60));

} else {
state.genTierTask = Bukkit.getServer().getScheduler().runTaskLater(MBedwarsTweaksPlugin.getInstance(), () -> {
currentLevel.broadcastEarn(arena, currentLevel.getAction().isMessageSupported());
currentLevel.getAction().getHandler().run(currentLevel, arena);
level.broadcastEarn(arena, level.getAction().isMessageSupported());
level.getAction().getHandler().run(level, arena);

scheduleNextTier(arena, tier + 1);
scheduleNextTier(arena, level.getTier() + 1);

}, (long) (currentLevel.getTime() * 20 * 60));
}, (long) (time * 20 * 60));
}
}

public static void scheduleNextTier(Arena arena, int tier) {
final GenTierLevel level = GenTiersConfig.gen_tier_levels.get(tier);

if (level == null)
return;

scheduleNextTier(arena, level, level.getTime());
}

// Custom format for hologram titles
public static void formatHoloTiles(String tierName, Spawner spawner) {
final String spawnerName = spawner.getDropType().getConfigName();
Expand All @@ -124,6 +134,7 @@ public static void formatHoloTiles(String tierName, Spawner spawner) {
}

public static class GenTierState {

@Getter
private String nextTierName = null;
private long nextUpdateTime = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void createNewDragon(Arena arena, @Nullable Team team, Location ar
final World world = arena.getGameWorld();

if (world == null)
throw new RuntimeException("Sudden death dragon tried to spawn in an arena with no game world?!?!?! WTF how did we get here in life?");
throw new RuntimeException("Sudden death dragon tried to spawn in an arena with no game world?!?!?!? WTF how did we get here in life?");

Location location = getDragonSpawn(arena, world, team);

Expand Down
Loading