Skip to content

Commit

Permalink
New options and lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed May 15, 2023
1 parent 98e1ff2 commit 2ded61e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/main/java/me/despical/oitc/ConfigPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public enum Option {
BLOCK_COMMANDS, BOSS_BAR_ENABLED, BUNGEE_ENABLED(false), CHAT_FORMAT_ENABLED, DATABASE_ENABLED(false),
DISABLE_FALL_DAMAGE(false), DISABLE_LEAVE_COMMAND(false), DISABLE_SEPARATE_CHAT(false),
ENABLE_SHORT_COMMANDS, IGNORE_WARNING_MESSAGES(false), INVENTORY_MANAGER_ENABLED, NAME_TAGS_HIDDEN,
REWARDS_ENABLED(false), SEND_SETUP_TIPS, SIGNS_BLOCK_STATES_ENABLED, UPDATE_NOTIFIER_ENABLED;
REWARDS_ENABLED(false), SEND_SETUP_TIPS, SIGNS_BLOCK_STATES_ENABLED, UPDATE_NOTIFIER_ENABLED,
REGEN_ENABLED(false), LEVEL_COUNTDOWN_ENABLED(false);

final String path;
final boolean def;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/despical/oitc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Main extends JavaPlugin {
public void onEnable() {
this.forceDisable = validateIfPluginShouldStart();

if (!forceDisable) {
if (forceDisable) {
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand All @@ -98,18 +98,18 @@ private boolean validateIfPluginShouldStart() {
if (!VersionResolver.isCurrentBetween(VersionResolver.ServerVersion.v1_8_R3, VersionResolver.ServerVersion.v1_19_R3)) {
getLogger().info("Your server version is not supported by One in the Chamber!");
getLogger().info("Sadly, we must shut off. Maybe you consider changing your server version?");
return false;
return true;
}

try {
Class.forName("org.spigotmc.SpigotConfig");
} catch (Exception exception) {
getLogger().info("Your server software is not supported by One in the Chamber!");
getLogger().info("We support only Spigot and Spigot forks only! Shutting off...");
return false;
return true;
}

return true;
return false;
}

@Override
Expand All @@ -130,7 +130,7 @@ public void onDisable() {
AttributeUtils.resetAttackCooldown(player);

arena.teleportToEndLocation(player);
arena.doBarAction(Arena.BarAction.REMOVE, player);
arena.doBarAction(0, player);
arena.getScoreboardManager().removeScoreboard(player);

player.setFlySpeed(.1F);
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/me/despical/oitc/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package me.despical.oitc.arena;

import me.despical.commons.compat.Titles;
import me.despical.commons.compat.VersionResolver;
import me.despical.commons.miscellaneous.AttributeUtils;
import me.despical.commons.miscellaneous.PlayerUtils;
import me.despical.commons.serializer.InventorySerializer;
Expand Down Expand Up @@ -81,7 +80,7 @@ public Arena(String id) {
arenaOptions.put(option, option.getDefaultValue());
}

if (VersionResolver.isCurrentHigher(VersionResolver.ServerVersion.v1_8_R3) && plugin.getConfigPreferences().getOption(ConfigPreferences.Option.BOSS_BAR_ENABLED)) {
if (!ArenaUtils.isLegacy() && plugin.getConfigPreferences().getOption(ConfigPreferences.Option.BOSS_BAR_ENABLED)) {
gameBar = plugin.getServer().createBossBar(chatManager.message("boss_bar.main_title"), BarColor.BLUE, BarStyle.SOLID);
}

Expand Down Expand Up @@ -217,10 +216,10 @@ public void teleportToLobby(Player player) {
player.teleport(location);
}

public void doBarAction(BarAction action, Player p) {
public void doBarAction(int action, Player p) {
if (gameBar == null) return;

if (action == BarAction.ADD) {
if (action == 1) {
gameBar.addPlayer(p);
} else {
gameBar.removePlayer(p);
Expand Down Expand Up @@ -345,9 +344,10 @@ public void run() {
gameBar.setTitle(chatManager.message("boss_bar.starting_in").replace("%time%", Integer.toString(getTimer())));
}

for (Player player : players) {
player.setLevel(getTimer());
player.setExp((float) (getTimer() / waitingTime));
if (plugin.getConfigPreferences().getOption(ConfigPreferences.Option.LEVEL_COUNTDOWN_ENABLED)) {
for (Player player : players) {
player.setLevel(getTimer());
}
}

if (size < minPlayers) {
Expand Down Expand Up @@ -451,7 +451,7 @@ public void run() {
player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));

teleportToEndLocation(player);
doBarAction(BarAction.REMOVE, player);
doBarAction(0, player);
}

plugin.getRewardsFactory().performReward(this, Reward.RewardType.END_GAME);
Expand All @@ -461,7 +461,6 @@ public void run() {
}

setArenaState(ArenaState.RESTARTING);
broadcastMessage(chatManager.prefixedMessage("commands.teleported-to-the-lobby"));
break;
case RESTARTING:
plugin.getUserManager().getUsers(this).forEach(user -> user.setSpectator(false));
Expand All @@ -486,10 +485,6 @@ public void run() {
}
}

public enum BarAction {
ADD, REMOVE
}

public enum GameLocation {
LOBBY, END
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/me/despical/oitc/arena/ArenaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void joinAttempt(Player player, Arena arena) {
AttributeUtils.setAttackCooldown(player, plugin.getConfig().getDouble("Hit-Cooldown-Delay", 4));

arena.teleportToLobby(player);
arena.doBarAction(Arena.BarAction.ADD, player);
arena.doBarAction(1, player);
arena.showPlayers();
ArenaUtils.showPlayer(player, arena);

Expand Down Expand Up @@ -208,7 +208,7 @@ public static void leaveAttempt(Player player, Arena arena) {

user.setSpectator(false);
arena.getScoreboardManager().removeScoreboard(player);
arena.doBarAction(Arena.BarAction.REMOVE, player);
arena.doBarAction(0, player);

player.getInventory().clear();
player.getInventory().setArmorContents(null);
Expand All @@ -224,7 +224,7 @@ public static void leaveAttempt(Player player, Arena arena) {
player.setGameMode(GameMode.SURVIVAL);
player.getInventory().setHeldItemSlot(4); // change slot to not trigger something else

if (arena.getArenaState() != ArenaState.WAITING_FOR_PLAYERS && arena.getArenaState() != ArenaState.STARTING && arena.getPlayers().isEmpty()) {
if (!arena.isArenaState(ArenaState.WAITING_FOR_PLAYERS, ArenaState.STARTING) && arena.getPlayers().isEmpty()) {
arena.setArenaState(ArenaState.ENDING);
arena.setTimer(0);
}
Expand Down Expand Up @@ -276,12 +276,14 @@ public static void stopGame(boolean quickStop, Arena arena) {
Titles.sendTitle(player, chatManager.message("in_game.messages.game_end_messages.titles.win"), chatManager.message("in_game.messages.game_end_messages.subtitles.win").replace("%winner%", topPlayerName));

plugin.getRewardsFactory().performReward(player, Reward.RewardType.WIN);
} else if (!user.isSpectator()) {
user.addStat(StatsStorage.StatisticType.LOSES, 1);

} else {
Titles.sendTitle(player, chatManager.message("in_game.messages.game_end_messages.titles.lose"), chatManager.message("in_game.messages.game_end_messages.subtitles.lose").replace("%winner%", topPlayerName));

plugin.getRewardsFactory().performReward(player, Reward.RewardType.LOSE);
if (!user.isSpectator()) {
user.addStat(StatsStorage.StatisticType.LOSES, 1);

plugin.getRewardsFactory().performReward(player, Reward.RewardType.LOSE);
}
}

plugin.getUserManager().saveAllStatistic(user);
Expand Down
40 changes: 22 additions & 18 deletions src/main/java/me/despical/oitc/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -293,20 +288,20 @@ public void onHangingBreakEvent(HangingBreakByEntityEvent event) {

@EventHandler
public void onDamageEntity(EntityDamageByEntityEvent e) {
if (!(e.getEntity() instanceof Player && e.getDamager() instanceof Arrow)) {
return;
}
if (!(e.getEntity() instanceof Player && e.getDamager() instanceof Arrow)) return;

Arrow arrow = (Arrow) e.getDamager();

if (!(arrow.getShooter() instanceof Player)) {
return;
}
if (!(arrow.getShooter() instanceof Player)) return;

Player shooter = (Player) arrow.getShooter();
Player player = (Player) e.getEntity();

if (ArenaRegistry.isInArena((Player) e.getEntity()) && ArenaRegistry.isInArena((Player) arrow.getShooter())) {
if (!e.getEntity().getName().equals(((Player) arrow.getShooter()).getName())) {
if (ArenaRegistry.isInArena(player) && ArenaRegistry.isInArena(shooter)) {
if (!player.getUniqueId().equals(shooter.getUniqueId())) {
e.setDamage(100.0);
plugin.getRewardsFactory().performReward((Player) e.getEntity(), Reward.RewardType.DEATH);

plugin.getRewardsFactory().performReward(player, Reward.RewardType.DEATH);
} else {
e.setCancelled(true);
}
Expand All @@ -328,7 +323,7 @@ public void onDeath(PlayerDeathEvent e) {
e.getEntity().getLocation().getWorld().playEffect(e.getEntity().getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
e.getEntity().playEffect(org.bukkit.EntityEffect.HURT);

Titles.sendTitle(victim.getKiller(), null, chatManager.message("in_game.messages.score_subtitle"));
Titles.sendTitle(victim.getKiller(), "", chatManager.message("in_game.messages.score_subtitle"));

User victimUser = userManager.getUser(victim);
victimUser.setStat(StatsStorage.StatisticType.LOCAL_KILL_STREAK, 0);
Expand All @@ -340,7 +335,7 @@ public void onDeath(PlayerDeathEvent e) {
killerUser.addStat(StatsStorage.StatisticType.LOCAL_KILLS, 1);
killerUser.addStat(StatsStorage.StatisticType.KILLS, 1);

if (killerUser.getStat(StatsStorage.StatisticType.LOCAL_KILL_STREAK) == 1){
if (killerUser.getStat(StatsStorage.StatisticType.LOCAL_KILL_STREAK) == 1) {
arena.broadcastMessage(chatManager.prefixedFormattedMessage(arena, chatManager.message("in_game.messages.death").replace("%killer%", victim.getKiller().getName()), victim));
} else {
arena.broadcastMessage(chatManager.prefixedFormattedMessage(arena, chatManager.message("in_game.messages.kill_streak").replace("%kill_streak%", Integer.toString(killerUser.getStat(StatsStorage.StatisticType.LOCAL_KILL_STREAK))).replace("%killer%", victim.getKiller().getName()), victim));
Expand All @@ -365,11 +360,20 @@ public void onRespawn(PlayerRespawnEvent event) {

event.setRespawnLocation(arena.getRandomSpawnPoint());

Titles.sendTitle(player, null, chatManager.message("in_game.messages.death_subtitle"));
Titles.sendTitle(player, "", chatManager.message("in_game.messages.death_subtitle"));

ItemPosition.giveKit(player);
}

@EventHandler
public void onHealthRegen(EntityRegainHealthEvent event) {
if (!(event.getEntity() instanceof Player)) return;

if (!plugin.getConfigPreferences().getOption(ConfigPreferences.Option.REGEN_ENABLED)) {
event.setCancelled(true);
}
}

@EventHandler
public void onInteractWithArmorStand(PlayerArmorStandManipulateEvent event) {
if (ArenaRegistry.isInArena(event.getPlayer())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

/**
* @author Despical
Expand All @@ -53,7 +52,7 @@ private void registerItems() {
final ConfigurationSection section = config.getConfigurationSection("items");

if (section == null) {
plugin.getLogger().log(Level.WARNING, "Couldn't find 'items' section in items.yml, delete the file to regenerate it!");
plugin.getLogger().warning("Couldn't find 'items' section in items.yml, delete the file to regenerate it!");
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Winning-Score: 25
# If this option is enabled, players will only be allowed to execute OITC associated commands.
Block-Commands: true

# Should we cancel health regeneration?
Regen-Enabled: false

# Should we change player's level with timer?
Level-Countdown-Enabled: false

# Should we fire some cool fireworks at location of every player after the game ends?
Firework-When-Game-Ends: true

Expand Down
14 changes: 8 additions & 6 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,18 @@ In-Game:
Win: "&e%winner%"
Lose: "&c%winner% &awon the game!"
Summary-Message:
- "&a&m----------------------------------------------------"
- "&e&lOne in the Chamber"
- "&a&m-------------------------------------------------"
- "&f&lOne in the Chamber"
- ""
- "&f&l%winner% &e&lWINNER! (%winner_score%)"
- ""
- "&8&lRank: &7&l%rank%"
- "&8&lScore: &7&l%score%"
- "&8&lDeaths: &7&l%deaths%"
- "&n&lYour Statistics:"
- ""
- "&a&m----------------------------------------------------"
- "&7Rank: %rank%"
- "&7Score: %score%"
- "&7Deaths: %deaths%"
- ""
- "&a&m-------------------------------------------------"
Admin-Messages:
Set-Starting-In-To-0: "&bAn admin set waiting time to 0. The game starts now!"
Stopped-Game: "&bAn admin has been force stopped the game by command!"
Expand Down

0 comments on commit 2ded61e

Please sign in to comment.