Skip to content

Commit

Permalink
v3.5.1 - spectator mode revert, random queue join option, lang.yml me…
Browse files Browse the repository at this point in the history
…ssage placeholders and more
  • Loading branch information
Realizedd committed Jan 9, 2022
1 parent 3a50181 commit 3e4c0ca
Show file tree
Hide file tree
Showing 29 changed files with 403 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ Maven:
#### Dependency
Gradle:
```groovy
compile group: 'com.github.Realizedd.Duels', name: 'duels-api', version: '3.5.0'
compile group: 'com.github.Realizedd.Duels', name: 'duels-api', version: '3.5.1'
```

Maven:
```xml
<dependency>
<groupId>com.github.Realizedd.Duels</groupId>
<artifactId>duels-api</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {

allprojects {
group 'me.realized'
version '3.5.0'
version '3.5.1'
}

subprojects {
Expand Down Expand Up @@ -47,8 +47,8 @@ subprojects {
}

maven {
name 'sk89q-repo'
url 'https://maven.sk89q.com/repo/'
name 'enginehub-repo'
url 'https://maven.enginehub.org/repo/'
}

maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.UUID;
import me.realized.duels.api.arena.Arena;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Represents a Spectator spectating a match.
Expand All @@ -19,6 +21,33 @@ public interface Spectator {
@NotNull
UUID getUuid();

/**
* The {@link Player} instance of this spectator.
*
* @return The {@link Player} instance of this spectator or null if player is not online.
* @since 3.5.1
*/
@Nullable
Player getPlayer();

/**
* The {@link UUID} of the player this spectator is spectating.
*
* @return {@link UUID} of the player this spectator is spectating.
* @since 3.5.1
*/
@NotNull
UUID getTargetUuid();

/**
* The {@link Player} instance of the player this spectator is spectating.
*
* @return The {@link Player} instance of player this spectator is spectating or null if player is not online.
* @since 3.5.1
*/
@Nullable
Player getTarget();

/**
* The {@link Arena} this spectator is spectating.
*
Expand Down
1 change: 0 additions & 1 deletion duels-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.apache.tools.ant.filters.ReplaceTokens

clean.doFirst {
delete "$rootDir/out/"
println "Running clean!"
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public boolean isBoundless() {
return kits.isEmpty();
}

public boolean isBound(final KitImpl kit) {
return kits.contains(kit);
public boolean isBound(@Nullable final KitImpl kit) {
return kit != null && kits.contains(kit);
}

public void bind(final KitImpl kit) {
Expand Down Expand Up @@ -243,10 +243,10 @@ public void onClick(final Player player) {
}

final Settings settings = settingManager.getSafely(player);
final KitImpl kit = settings.getKit();
final String kitName = settings.getKit() != null ? settings.getKit().getName() : lang.getMessage("GENERAL.none");

if (kit != null && !arenaManager.isSelectable(kit, this)) {
lang.sendMessage(player, "ERROR.setting.arena-not-applicable", "kit", kit.getName());
if (!arenaManager.isSelectable(settings.getKit(), this)) {
lang.sendMessage(player, "ERROR.setting.arena-not-applicable", "kit", kitName, "arena", name);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ public long getPlayersInMatch(final Queue queue) {
return arenas.stream().filter(arena -> arena.isUsed() && arena.getMatch().isFromQueue() && arena.getMatch().getSource().equals(queue)).count() * 2;
}

public boolean isSelectable(final KitImpl kit, final ArenaImpl arena) {
public boolean isSelectable(@Nullable final KitImpl kit, @NotNull final ArenaImpl arena) {
if (!arena.isAvailable()) {
return false;
}

if (kit == null) {
return true;
}

if (arena.isBoundless()) {
return !kit.isArenaSpecific();
if (kit == null) {
return true;
} else {
return !kit.isArenaSpecific();
}
}

return arena.isBound(kit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import me.realized.duels.DuelsPlugin;
import me.realized.duels.Permissions;
import me.realized.duels.api.spectate.SpectateManager.Result;
import me.realized.duels.arena.ArenaImpl;
import me.realized.duels.arena.MatchImpl;
import me.realized.duels.command.BaseCommand;
import me.realized.duels.spectate.SpectatorImpl;
import me.realized.duels.util.inventory.InventoryUtil;
Expand Down Expand Up @@ -63,7 +65,22 @@ protected void execute(final CommandSender sender, final String label, final Str
lang.sendMessage(player, "ERROR.spectate.not-in-match", "name", target.getName());
return;
case SUCCESS:
lang.sendMessage(player, "COMMAND.spectate.start-spectate", "name", target.getName());
final ArenaImpl arena = arenaManager.get(target);

// Meaningless checks to halt IDE warnings as target is guaranteed to be in a match if result is SUCCESS.
if (arena == null || arena.getMatch() == null) {
return;
}

final MatchImpl match = arena.getMatch();
final String kit = match.getKit() != null ? match.getKit().getName() : lang.getMessage("GENERAL.none");
lang.sendMessage(player, "COMMAND.spectate.start-spectate",
"name", target.getName(),
"opponent", arena.getOpponent(target).getName(),
"kit", kit,
"arena", arena.getName(),
"bet_amount", match.getBet()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ protected boolean executeFirst(final CommandSender sender, final String label, f
}

final Settings settings = settingManager.getSafely(player);
// Reset bet and own inventory to prevent accidents
// Reset bet to prevent accidents
settings.setBet(0);
settings.setOwnInventory(false);

settings.setTarget(target);
settings.setBaseLoc(player);
settings.setDuelzone(player, duelzone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
public class JoinCommand extends BaseCommand {

public JoinCommand(final DuelsPlugin plugin) {
super(plugin, "join", "join [-:kit] [bet]", "Joins a queue.", Permissions.QUEUE, 3, true, "j");
super(plugin, "join", "join [-:kit] [bet]", "Joins a queue.", Permissions.QUEUE, 2, true, "j");
}

@Override
protected void execute(final CommandSender sender, final String label, final String[] args) {
final Player player = (Player) sender;
KitImpl kit = null;

if (!args[1].equals("-")) {
if (!args[1].startsWith("-")) {
String name = StringUtil.join(args, " ", 1, args.length - (args.length > 2 ? 1 : 0)).replace("-", " ");
kit = kitManager.get(name);

Expand All @@ -36,7 +36,7 @@ protected void execute(final CommandSender sender, final String label, final Str

final String kitName = kit != null ? kit.getName() : lang.getMessage("GENERAL.none");
final int bet = args.length > 2 ? NumberUtil.parseInt(args[args.length - 1]).orElse(0) : 0;
final Queue queue = queueManager.get(kit, bet);
final Queue queue = args[1].equals("-r") ? queueManager.randomQueue() : queueManager.get(kit, bet);

if (queue == null) {
lang.sendMessage(sender, "ERROR.queue.not-found", "bet_amount", bet, "kit", kitName);
Expand Down
11 changes: 11 additions & 0 deletions duels-plugin/src/main/java/me/realized/duels/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
@Getter
private List<String> blacklistedCommands;

@Getter
private List<String> queueBlacklistedCommands;

@Getter
private boolean ratingEnabled;
@Getter
Expand All @@ -158,6 +161,10 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
@Getter
private boolean specRequiresClearedInventory;
@Getter
private boolean specUseSpectatorGamemode;
@Getter
private boolean specAddInvisibilityEffect;
@Getter
private List<String> specWhitelistedCommands;

@Getter
Expand Down Expand Up @@ -318,12 +325,16 @@ protected void loadValues(FileConfiguration configuration) throws Exception {
whitelistedCommands = configuration.getStringList("duel.whitelisted-commands");
blacklistedCommands = configuration.getStringList("duel.blacklisted-commands");

queueBlacklistedCommands = configuration.getStringList("queue.blacklisted-commands");

ratingEnabled = configuration.getBoolean("rating.enabled", true);
kFactor = Math.max(configuration.getInt("rating.k-factor", 32), 1);
defaultRating = Math.max(configuration.getInt("rating.default-rating", 1400), 0);
ratingQueueOnly = configuration.getBoolean("rating.queue-matches-only", true);

specRequiresClearedInventory = configuration.getBoolean("spectate.requires-cleared-inventory", false);
specUseSpectatorGamemode = configuration.getBoolean("spectate.use-spectator-gamemode", false);
specAddInvisibilityEffect = configuration.getBoolean("spectate.add-invisibility-effect", true);
specWhitelistedCommands = configuration.getStringList("spectate.whitelisted-commands");

cdEnabled = configuration.getBoolean("countdown.enabled", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import me.realized.duels.util.compat.CompatUtil;
import me.realized.duels.util.compat.Identifiers;
import me.realized.duels.util.inventory.ItemBuilder;
import me.realized.duels.util.inventory.ItemUtil;
import me.realized.duels.util.json.DefaultBasedDeserializer;
import me.realized.duels.util.yaml.YamlUtil;
import org.bukkit.Material;
Expand Down Expand Up @@ -103,6 +104,10 @@ public ItemData deserialize(final JsonParser parser, final DeserializationContex
return null;
}

if (node.has("serializedItem")) {
return new ItemData(ItemUtil.itemFrom64(node.get("serializedItem").textValue()));
}

final String material = node.get("material").textValue();
final int amount = node.has("amount") ? node.get("amount").intValue() : 1;
final short damage = node.has("data") ? node.get("data").shortValue() : 0;
Expand Down Expand Up @@ -200,7 +205,7 @@ public ItemData deserialize(final JsonParser parser, final DeserializationContex
));
}

data = new ItemData(builder.build());
return new ItemData(builder.build());
}

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void handleLoad() {
names.putIfAbsent(user.getName().toLowerCase(), uuid);
users.putIfAbsent(uuid, user);
} catch (IOException ex) {
Log.error(this, "Failed to load data of " + uuid + "!", ex);
Log.error(this, "Could not load userdata from file: " + fileName, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void startMatch(final Player first, final Player second, final Settings s
}

if (kit != null && !arenaManager.isSelectable(kit, arena)) {
lang.sendMessage(Arrays.asList(first, second), "DUEL.start-failure.arena-not-applicable");
lang.sendMessage(Arrays.asList(first, second), "DUEL.start-failure.arena-not-applicable", "kit", kit.getName(), "arena", arena.getName());
refundItems(items, first, second);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public void onClick(final Player player) {
return;
}

if (!config.isKitSelectingEnabled()) {
lang.sendMessage(player, "ERROR.duel.mode-fixed");
return;
}

final Settings settings = settingManager.getSafely(player);
settings.setOwnInventory(!settings.isOwnInventory());
settings.updateGui(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void onClick(final Player player) {

if (!settings.isOwnInventory() && settings.getKit() == null) {
player.closeInventory();
lang.sendMessage(player, "ERROR.duel.mode-unselected");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public VaultHook(final DuelsPlugin plugin) {
}

economy = provider.getProvider();
Log.info("Using Economy Provider: " + economy.getClass().getName());
}

public boolean has(final int amount, final Player... players) {
Expand Down
12 changes: 12 additions & 0 deletions duels-plugin/src/main/java/me/realized/duels/kit/KitImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public ItemStack getDisplayed() {
return super.getDisplayed();
}

@Override
public void setDisplayed(final ItemStack displayed) {
super.setDisplayed(displayed);
kitManager.saveKits();
}

public boolean hasCharacteristic(final Characteristic characteristic) {
return characteristics.contains(characteristic);
}
Expand Down Expand Up @@ -113,6 +119,12 @@ public void onClick(final Player player) {
}

final Settings settings = settingManager.getSafely(player);

if (settings.getArena() != null && !arenaManager.isSelectable(this, settings.getArena())) {
lang.sendMessage(player, "ERROR.setting.arena-not-applicable", "kit", name, "arena", settings.getArena().getName());
return;
}

settings.setKit(this);
settings.openGui(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import lombok.Getter;
import me.realized.duels.DuelsPlugin;
import me.realized.duels.api.event.queue.QueueCreateEvent;
Expand Down Expand Up @@ -55,6 +56,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -242,6 +244,11 @@ public Queue get(@NotNull final Player player) {
return queues.stream().filter(queue -> queue.isInQueue(player)).findFirst().orElse(null);
}

@Nullable
public Queue randomQueue() {
return !queues.isEmpty() ? queues.get(ThreadLocalRandom.current().nextInt(queues.size())) : null;
}

@Nullable
@Override
public Queue create(@Nullable final CommandSender source, @Nullable final Kit kit, final int bet) {
Expand Down Expand Up @@ -402,4 +409,16 @@ public Queue remove(final Player player) {
public void on(final PlayerQuitEvent event) {
remove(event.getPlayer());
}

@EventHandler(ignoreCancelled = true)
public void on(final PlayerCommandPreprocessEvent event) {
final String command = event.getMessage().substring(1).split(" ")[0].toLowerCase();

if (!isInQueue(event.getPlayer()) || !config.getQueueBlacklistedCommands().contains(command)) {
return;
}

event.setCancelled(true);
lang.sendMessage(event.getPlayer(), "QUEUE.prevent.command", "command", event.getMessage());
}
}
Loading

0 comments on commit 3e4c0ca

Please sign in to comment.