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

Fixed buy group tracker not working with rejoins + misc improvements #27

Merged
merged 1 commit into from
Feb 25, 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
@@ -1,54 +1,33 @@
package me.metallicgoat.tweaksaddon.tweaks.advancedswords;

import de.marcely.bedwars.api.GameAPI;
import de.marcely.bedwars.api.arena.Arena;
import de.marcely.bedwars.api.game.shop.BuyGroup;
import java.util.HashMap;

import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;

public class BuyGroupTracker {

private final Map<Player, Map<String, Integer>> trackBuyGroupMap = new HashMap<>();

public BuyGroupTracker(Arena arena){
if(arena == null)
return;

// Load Players
for(Player player : arena.getPlayers())
loadDefaultPlayerBuyGroups(player);
}

private void loadDefaultPlayerBuyGroups(Player player) {
final HashMap<String, Integer> map = new HashMap<>();

for (BuyGroup group : GameAPI.get().getBuyGroups())
map.put(group.getName(), 0);
private final Map<UUID, Map<String, Integer>> trackBuyGroupMap = new HashMap<>();

trackBuyGroupMap.put(player, map);
public void upgradeLevel(BuyGroup group, int newLevel, Player player) {
setBuyGroupLevel(player, group.getName(), newLevel);
}

public void upgradeLevel(BuyGroup group, int newLevel, Player player){
if (!trackBuyGroupMap.containsKey(player))
return;

// Increment if necessary
trackBuyGroupMap.get(player).put(group.getName(), newLevel);
}
public int getBuyGroupLevel(Player player, String buyGroup) {
final Map<String, Integer> map = trackBuyGroupMap.get(player.getUniqueId());

public int getBuyGroupLevel(Player player, String buyGroup){
if (!trackBuyGroupMap.containsKey(player))
if (map == null)
return 0;

return trackBuyGroupMap.get(player).getOrDefault(buyGroup, 0);
return map.getOrDefault(buyGroup, 0);
}

public void setBuyGroupLevel(Player player, String buyGroup, int level){
if (!trackBuyGroupMap.containsKey(player))
return;
public void setBuyGroupLevel(Player player, String buyGroup, int level) {
final Map<String, Integer> map = this.trackBuyGroupMap.computeIfAbsent(
player.getUniqueId(),
g0 -> new HashMap<>());

trackBuyGroupMap.get(player).put(buyGroup, level);
map.put(buyGroup, level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import me.metallicgoat.tweaksaddon.integration.DependType;
import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin;
import me.metallicgoat.tweaksaddon.config.SwordsToolsConfig;
import me.metallicgoat.tweaksaddon.integration.DependencyLoader;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -52,7 +51,7 @@ public static void load() {
public static void onRoundStart(RoundStartEvent event) {
final Arena arena = event.getArena();

buyGroupTrackerMap.put(arena, new BuyGroupTracker(arena));
buyGroupTrackerMap.put(arena, new BuyGroupTracker());
}

@EventHandler
Expand Down Expand Up @@ -89,7 +88,7 @@ public static BuyGroupTracker getBuyGroupTracker(Player player) {

public static BuyGroupTracker getBuyGroupTracker(Arena arena) {
if(arena == null || !buyGroupTrackerMap.containsKey(arena))
return new BuyGroupTracker(null);
return new BuyGroupTracker();

return buyGroupTrackerMap.get(arena);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.marcely.bedwars.api.GameAPI;
import de.marcely.bedwars.api.arena.Arena;
import de.marcely.bedwars.api.event.player.PlayerQuitArenaEvent;
import java.util.IdentityHashMap;
import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin;
import me.metallicgoat.tweaksaddon.config.MainConfig;
import org.bukkit.Bukkit;
Expand All @@ -15,12 +16,11 @@
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.Map;

public class ExplosiveFallDamageMultiplier implements Listener {

private final Map<Player, ExplodeInfo> explodedPlayers = new HashMap<>();
private final Map<Player, ExplodeInfo> explodedPlayers = new IdentityHashMap<>();

@EventHandler
public void onDamage(EntityDamageEvent event) {
Expand All @@ -45,10 +45,10 @@ public void onDamage(EntityDamageEvent event) {

@EventHandler
public void onPlayerQuit(PlayerQuitArenaEvent event) {
final Player player = event.getPlayer();
final ExplodeInfo explodeInfo = this.explodedPlayers.remove(event.getPlayer());

if (this.explodedPlayers.containsKey(player))
this.explodedPlayers.remove(player).removeTask.cancel();
if (explodeInfo != null)
explodeInfo.removeTask.cancel();
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import de.marcely.bedwars.api.arena.Team;
import de.marcely.bedwars.api.event.arena.ArenaDeleteEvent;
import de.marcely.bedwars.api.event.arena.ArenaStatusChangeEvent;
import de.marcely.bedwars.api.event.arena.RoundEndEvent;
import de.marcely.bedwars.api.event.arena.RoundStartEvent;
import de.marcely.bedwars.api.message.Message;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
import de.marcely.bedwars.api.arena.ArenaStatus;
import de.marcely.bedwars.api.event.player.PlayerPickupDropEvent;
import de.marcely.bedwars.api.event.player.PlayerQuitArenaEvent;
import java.util.IdentityHashMap;
import java.util.Map;
import me.metallicgoat.tweaksaddon.config.MainConfig;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;

import java.util.HashMap;

public class AFKSpawners implements Listener {

private final Map<Player, Long> moveTimes = new HashMap<>();
private final Map<Player, Long> moveTimes = new IdentityHashMap<>();

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Expand Down
Loading