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

Add damage check for time of duel out & Boxing & Clear drop items & Tie commands #115

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ subprojects {
repositories {
mavenCentral()

maven {
name = 'citizens-repo'
url = 'https://maven.citizensnpcs.co/repo'
}

maven {
name 'spigot-repo'
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
Expand Down
2 changes: 1 addition & 1 deletion duels-api/src/main/java/me/realized/duels/api/Duels.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface Duels extends Plugin {
*/
@NotNull
DQueueManager getQueueManager();


/**
* Gets the QueueSignManager singleton used by Duels.
Expand Down
4 changes: 4 additions & 0 deletions duels-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ processResources {
}

dependencies {
compileOnly('net.citizensnpcs:citizens-main:2.0.33-SNAPSHOT') {
exclude group: '*', module: '*'
}
compileOnly 'org.jetbrains:annotations-java5:22.0.0'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
Expand All @@ -29,6 +32,7 @@ dependencies {
}
implementation name: 'Vault-1.6.7'
implementation name: 'CombatTagPlus'
implementation name: 'AntiRelog-3.0.11'
implementation name: 'PvPManager-3.7.16'
implementation name: 'Factions-1.6.9.5-U0.1.14'
implementation name: 'MassiveCore'
Expand Down
2 changes: 2 additions & 0 deletions duels-plugin/src/main/java/me/realized/duels/DuelsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.realized.duels.arena.ArenaManagerImpl;
import me.realized.duels.betting.BettingManager;
import me.realized.duels.command.commands.SpectateCommand;
import me.realized.duels.command.commands.bot.BotDuelCommand;
import me.realized.duels.command.commands.duel.DuelCommand;
import me.realized.duels.command.commands.duels.DuelsCommand;
import me.realized.duels.command.commands.queue.QueueCommand;
Expand Down Expand Up @@ -228,6 +229,7 @@ public void onDisable() {
private boolean load() {
registerCommands(
new DuelCommand(this),
new BotDuelCommand(this),
new QueueCommand(this),
new SpectateCommand(this),
new DuelsCommand(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public final class Permissions {

public static final String DUEL = "duels.duel";
public static final String DUEL_BOT = "duels.duel.bot";
public static final String STATS = "duels.stats";
public static final String STATS_OTHERS = STATS + ".others";
public static final String TOGGLE = "duels.toggle";
Expand Down
54 changes: 50 additions & 4 deletions duels-plugin/src/main/java/me/realized/duels/arena/ArenaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
import me.realized.duels.util.inventory.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -45,7 +49,7 @@ public class ArenaImpl extends BaseButton implements Arena {
private final Map<Integer, Location> positions = new HashMap<>();
@Getter
private MatchImpl match;
@Getter(value = AccessLevel.PACKAGE)
@Getter
@Setter(value = AccessLevel.PACKAGE)
private Countdown countdown;
@Getter
Expand Down Expand Up @@ -164,6 +168,48 @@ public void endMatch(final UUID winner, final UUID loser, final Reason reason) {

final Queue source = match.getSource();
match.setFinished();

for(Block block : match.placedBlocks) {
block.setType(Material.AIR);
}

for(Map.Entry<Location, BlockData> map : match.brokenBlocks.entrySet()) {
map.getKey().getBlock().setBlockData(map.getValue());
}

for (Block block : match.liquids) {
Location loc = block.getLocation();
int radius = 1;

while (true) {
boolean waterFound = false;

for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
Block findBlock = loc.clone().add(x, y, z).getBlock();
String type = findBlock.getType().name().toLowerCase();

if (type.contains("water") || type.contains("lava") || type.contains("cobblestone") || type.contains("obsidian")) {
waterFound = true;
findBlock.setType(Material.AIR);
}
}
}
}

if (!waterFound) {
break;
}

radius++;
}
}

if(config.isClearItemsAfterMatch()) {
match.droppedItems.forEach(Entity::remove);
}

match = null;

if (source != null) {
Expand Down Expand Up @@ -192,18 +238,18 @@ boolean isCounting() {
@Override
public boolean has(@NotNull final Player player) {
Objects.requireNonNull(player, "player");
return isUsed() && !match.getPlayerMap().getOrDefault(player, true);
return isUsed() && !match.getPlayerMap().getOrDefault(player, new MatchImpl.PlayerStatus(true)).isDead;
}

public void add(final Player player) {
if (isUsed()) {
match.getPlayerMap().put(player, false);
match.getPlayerMap().put(player, new MatchImpl.PlayerStatus(false));
}
}

public void remove(final Player player) {
if (isUsed() && match.getPlayerMap().containsKey(player)) {
match.getPlayerMap().put(player, true);
match.getPlayerMap().put(player, new MatchImpl.PlayerStatus(true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -230,19 +234,22 @@ public void clearBinds(final KitImpl kit) {

private class ArenaListener implements Listener {

@EventHandler(ignoreCancelled = true)
@EventHandler
public void on(final PlayerInteractEvent event) {
if (!event.hasBlock() || !config.isPreventInteract()) {
if(event.getAction() != Action.RIGHT_CLICK_AIR && event.isCancelled() || !config.isPreventInteract()) {
return;
}

final ArenaImpl arena = get(event.getPlayer());
Player player = event.getPlayer();

final ArenaImpl arena = get(player);

if (arena == null || !arena.isCounting()) {
return;
}

event.setCancelled(true);
player.updateInventory();
}

@EventHandler(ignoreCancelled = true)
Expand Down Expand Up @@ -274,7 +281,7 @@ public void on(final ProjectileLaunchEvent event) {

final ArenaImpl arena = get((Player) shooter);

if (arena == null || !arena.isCounting()) {
if (arena == null || !arena.isCounting() || event.getEntity().getClass().getName().contains("Potion")) {
return;
}

Expand All @@ -283,20 +290,29 @@ public void on(final ProjectileLaunchEvent event) {

@EventHandler(ignoreCancelled = true)
public void on(final PlayerMoveEvent event) {
final Location to = event.getTo();

if (!config.isPreventMovement()) {
return;
}

final Location from = event.getFrom();
final Location to = event.getTo();

if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) {
return;
}

final ArenaImpl arena = get(event.getPlayer());

if (arena == null || !arena.isCounting()) {
if (arena == null) {
return;
}

if(to.getBlockY() < config.getMinY()) {
event.getPlayer().damage(99999);
}

if(!arena.isCounting()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class Countdown extends BukkitRunnable {

@Override
public void run() {
if (finished) {
return;
}
if (finished) return;

final String rawMessage = messages.remove(0);
final String message = StringUtil.color(rawMessage);
Expand All @@ -44,7 +42,7 @@ public void run() {
arena.getPlayers().forEach(player -> {
config.playSound(player, rawMessage);

final Pair<String, Integer> info = this.info.get(player.getUniqueId());
final Pair<String, Integer> info = this.info.get(player.getUniqueId());

if (info != null) {
player.sendMessage(message
Expand Down
72 changes: 60 additions & 12 deletions duels-plugin/src/main/java/me/realized/duels/arena/MatchImpl.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
package me.realized.duels.arena;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Getter;
import me.realized.duels.api.match.Match;
import me.realized.duels.kit.KitImpl;
import me.realized.duels.queue.Queue;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class MatchImpl implements Match {

public static class PlayerStatus {

public PlayerStatus(boolean isDead) {
this.isDead = isDead;
}

// Player is dead value
public boolean isDead;
// How much damage to your opponent.
public double damageCount;

public int hits;

}

@Getter
private final ArenaImpl arena;
@Getter
Expand All @@ -35,8 +48,13 @@ public class MatchImpl implements Match {
@Getter
private boolean finished;

public List<Item> droppedItems = new ArrayList<>();
public List<Block> placedBlocks = new ArrayList<>();
public List<Block> liquids = new ArrayList<>();
public HashMap<Location, BlockData> brokenBlocks = new HashMap<>();

// Default value for players is false, which is set to true if player is killed in the match.
private final Map<Player, Boolean> players = new HashMap<>();
private final Map<Player, PlayerStatus> players = new HashMap<>();

MatchImpl(final ArenaImpl arena, final KitImpl kit, final Map<UUID, List<ItemStack>> items, final int bet, final Queue source) {
this.arena = arena;
Expand All @@ -47,20 +65,50 @@ public class MatchImpl implements Match {
this.source = source;
}

Map<Player, Boolean> getPlayerMap() {
Map<Player, PlayerStatus> getPlayerMap() {
return players;
}

Set<Player> getAlivePlayers() {
return players.entrySet().stream().filter(entry -> !entry.getValue()).map(Entry::getKey).collect(Collectors.toSet());
return players.entrySet().stream().filter(entry -> !entry.getValue().isDead).map(Entry::getKey).collect(Collectors.toSet());
}

public void addDamageToPlayer(Player player, double damage) {
PlayerStatus status = players.get(player);
status.damageCount += damage;
status.hits++;
}

public int getHits(Player player) {
return players.get(player).hits;
}

public Player getWinnerOfDamage() {
Player winner = players.entrySet()
.stream()
.max(Comparator.comparingDouble(entry -> entry.getValue().damageCount))
.map(Map.Entry::getKey)
.orElse(null);

return winner;
}

public Player getLooserOfDamage() {
Player looser = players.entrySet()
.stream()
.min(Comparator.comparingDouble(entry -> entry.getValue().damageCount))
.map(Map.Entry::getKey)
.orElse(null);

return looser;
}

public Set<Player> getAllPlayers() {
return players.keySet();
}

public boolean isDead(final Player player) {
return players.getOrDefault(player, true);
return players.getOrDefault(player, new PlayerStatus(true)).isDead;
}

public boolean isFromQueue() {
Expand Down
Loading