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

Minor refactoring & new twist #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,6 +20,7 @@
import me.gaagjescraft.network.team.manhunt.menus.handlers.RunnerTrackerMenuHandler;
import me.gaagjescraft.network.team.manhunt.menus.twist.ManhuntTwistVoteMenu;
import me.gaagjescraft.network.team.manhunt.utils.*;
import me.gaagjescraft.network.team.manhunt.utils.config.Config;
import me.gaagjescraft.network.team.manhunt.utils.platform.OriginalPlatformUtils;
import me.gaagjescraft.network.team.manhunt.utils.platform.PlatformUtils;
import org.bukkit.Bukkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.Lists;
import me.gaagjescraft.network.team.manhunt.Manhunt;
import me.gaagjescraft.network.team.manhunt.utils.Util;
import me.gaagjescraft.network.team.manhunt.utils.config.twist.EndMessagePlainTwistConfig;
import me.gaagjescraft.network.team.manhunt.utils.config.twist.PlainTwistConfig;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
Expand Down Expand Up @@ -286,21 +288,24 @@ private void doStartingCountdown() {
public void doEvent() {
if (game.getSelectedTwist() == TwistVote.RANDOM_YEET) {
ThreadLocalRandom random = ThreadLocalRandom.current();
PlainTwistConfig config = plugin.getCfg().randomYeetTwistConfig;

for (GamePlayer gp : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;
player.sendMessage(Util.c(plugin.getCfg().twistRandomYeetMessage));
player.sendMessage(Util.c(config.getMessage()));
if (!gp.isDead()) {
player.setVelocity(new Vector(random.nextDouble(-5, 5.1), random.nextDouble(1, 2.3), random.nextDouble(-5, 5.1)));
plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistRandomYeetTitle), 20, 50, 20);
plugin.getUtil().playSound(player, plugin.getCfg().twistRandomYeetSound, 1, 1);
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
}
}
game.determineNextEventTime();
} else if (game.getSelectedTwist() == TwistVote.SPEED_BOOST) {
game.setEventActive(true);
ThreadLocalRandom random = ThreadLocalRandom.current();
int rand = random.nextInt(1, 4);
PlainTwistConfig config = plugin.getCfg().speedBoostTwistConfig;

StringBuilder a = new StringBuilder();
a.append("I".repeat(Math.max(0, rand)));
Expand All @@ -309,9 +314,9 @@ public void doEvent() {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;

plugin.getUtil().playSound(player, plugin.getCfg().twistSpeedBoostSound, 1, 1);
plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistSpeedBoostTitle), 20, 50, 20);
player.sendMessage(Util.c(plugin.getCfg().twistSpeedBoostMessage.replaceAll("%strength%", a.toString())));
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
player.sendMessage(Util.c(config.getMessage().replaceAll("%strength%", a.toString())));
if (gp.getPlayerType() == PlayerType.RUNNER && !gp.isFullyDead()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 400, rand));
}
Expand All @@ -322,6 +327,8 @@ public void doEvent() {
}, 400);
} else if (game.getSelectedTwist() == TwistVote.GET_HIGH) {
game.setEventActive(true);
PlainTwistConfig config = plugin.getCfg().getHighTwistConfig;

for (GamePlayer onlinePlayer : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(onlinePlayer.getUuid());
if (player == null) {
Expand All @@ -335,8 +342,9 @@ public void doEvent() {
game.getWorld().getHighestBlockYAt(playerLocation) + 1.5,
playerLocation.getZ()));

plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistGetHighTitle), 20, 50, 20);
player.sendMessage(Util.c(plugin.getCfg().twistGetHighMessage));
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
player.sendMessage(Util.c(config.getMessage()));
Bukkit.getScheduler().runTaskLater(plugin, () -> {
game.setEventActive(false);
game.determineNextEventTime();
Expand All @@ -345,13 +353,15 @@ public void doEvent() {
}
} else if (game.getSelectedTwist() == TwistVote.BLINDNESS) {
game.setEventActive(true);
PlainTwistConfig config = plugin.getCfg().blindnessTwistConfig;

for (GamePlayer gp : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;

plugin.getUtil().playSound(player, plugin.getCfg().twistBlindnessSound, 1, 1);
plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistBlindnessTitle), 20, 50, 20);
player.sendMessage(Util.c(plugin.getCfg().twistBlindnessMessage));
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
player.sendMessage(Util.c(config.getMessage()));
if (gp.getPlayerType() == PlayerType.HUNTER && !gp.isFullyDead()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 200, 1));
}
Expand All @@ -364,16 +374,18 @@ public void doEvent() {
game.setEventActive(true);
game.getWorld().setStorm(true);
game.getWorld().setThundering(true);
EndMessagePlainTwistConfig config = plugin.getCfg().acidRainTwistConfig;

for (GamePlayer gp : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;
plugin.getUtil().playSound(player, plugin.getCfg().twistAcidRainSound, 1, 1);
player.sendMessage(Util.c(plugin.getCfg().twistAcidRainMessage));
plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistAcidRainTitle), 20, 50, 20);
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
player.sendMessage(Util.c(config.getMessage()));
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
}

Bukkit.getScheduler().runTaskLater(plugin, () -> {
game.sendMessage(null, Util.c(plugin.getCfg().twistAcidRainEndedMessage));
game.sendMessage(null, Util.c(config.getEndedMessage()));
game.setEventActive(false);
game.determineNextEventTime();
if (game.getWorld() != null) {
Expand All @@ -383,13 +395,15 @@ public void doEvent() {
}, 600);
} else if (game.getSelectedTwist() == TwistVote.HARDCORE) {
game.setEventActive(true);
EndMessagePlainTwistConfig config = plugin.getCfg().hardcoreTwistConfig;

for (GamePlayer gp : game.getOnlinePlayers(null)) {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;
if (!gp.isFullyDead()) player.setHealth(6);
plugin.getUtil().playSound(player, plugin.getCfg().twistHardcoreSound, 1, 1);
player.sendMessage(Util.c(plugin.getCfg().twistHardcoreMessage));
plugin.getUtil().sendTitle(player, Util.c(plugin.getCfg().twistHardcoreTitle), 20, 50, 20);
plugin.getUtil().playSound(player, config.getSound(), 1, 1);
player.sendMessage(Util.c(config.getMessage()));
plugin.getUtil().sendTitle(player, Util.c(config.getTitle()), 20, 50, 20);
}

Bukkit.getScheduler().runTaskLater(plugin, () -> {
Expand All @@ -399,7 +413,7 @@ public void doEvent() {
Player player = Bukkit.getPlayer(gp.getUuid());
if (player == null) continue;
player.setHealth(player.getMaxHealth());
player.sendMessage(Util.c(plugin.getCfg().twistHardcoreEndedMessage));
player.sendMessage(Util.c(config.getEndedMessage()));
}
}, 600);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.gaagjescraft.network.team.manhunt.menus.twist;

import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import me.gaagjescraft.network.team.manhunt.Manhunt;
Expand All @@ -10,6 +9,7 @@
import me.gaagjescraft.network.team.manhunt.games.TwistVote;
import me.gaagjescraft.network.team.manhunt.utils.LayoutUtils;
import me.gaagjescraft.network.team.manhunt.utils.Util;
import me.gaagjescraft.network.team.manhunt.utils.config.icon.IconConfig;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -26,8 +26,6 @@
import org.bukkit.potion.PotionType;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

public class ManhuntTwistVoteMenu implements Listener {

Expand Down Expand Up @@ -142,71 +140,31 @@ public void onClick(InventoryClickEvent e) {
}

private void addBuiltinTwists() {
addTwistItem(new TwistItem(
TwistVote.HARDCORE,
plugin.getCfg().twistVoteMenuHardcoreMaterial,
plugin.getCfg().twistVoteMenuHardcoreDisplayname,
plugin.getCfg().twistVoteMenuHardcoreLore
));

addTwistItem(new TwistItem(
TwistVote.EXTRA_HEALTH,
plugin.getCfg().twistVoteMenuExtraHealthMaterial,
plugin.getCfg().twistVoteMenuExtraHealthDisplayname,
plugin.getCfg().twistVoteMenuExtraHealthLore
));

addTwistItem(new TwistItem(
TwistVote.BLINDNESS,
plugin.getCfg().twistVoteMenuBlindnessMaterial,
plugin.getCfg().twistVoteMenuBlindnessDisplayname,
plugin.getCfg().twistVoteMenuBlindnessLore
));

addTwistItem(new TwistItem(
TwistVote.RANDOM_YEET,
plugin.getCfg().twistVoteMenuHardcoreMaterial,
plugin.getCfg().twistVoteMenuHardcoreDisplayname,
plugin.getCfg().twistVoteMenuHardcoreLore
));

addTwistItem(new TwistItem(
TwistVote.SPEED_BOOST,
plugin.getCfg().twistVoteMenuSpeedBoostMaterial,
plugin.getCfg().twistVoteMenuSpeedBoostDisplayname,
plugin.getCfg().twistVoteMenuSpeedBoostLore
));

addTwistItem(new TwistItem(
TwistVote.GET_HIGH,
plugin.getCfg().twistVoteMenuGetHighMaterial,
plugin.getCfg().twistVoteMenuGetHighDisplayname,
plugin.getCfg().twistVoteMenuGetHighLore
));

addTwistItem(new TwistItem(
TwistVote.ACID_RAIN,
plugin.getCfg().twistVoteMenuAcidRainMaterial,
plugin.getCfg().twistVoteMenuAcidRainDisplayname,
plugin.getCfg().twistvoteMenuAcidRainLore,
item -> {
ItemMeta meta = item.getItemMeta();
if (item.getType() == Material.TIPPED_ARROW
|| item.getType() == Material.POTION
|| item.getType() == Material.SPLASH_POTION
|| item.getType() == Material.LINGERING_POTION) {
assert meta != null;
((PotionMeta) meta).setBasePotionData(new PotionData(PotionType.POISON));
}

assert meta != null;
meta.setDisplayName(Util.c(plugin.getCfg().twistVoteMenuAcidRainDisplayname));

meta.setLore(Objects.requireNonNull(item.getItemMeta()).getLore());
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);
}
));
addTwistItem(new TwistItem(TwistVote.HARDCORE, plugin.getCfg().hardcoreTwistConfig.getIcon()));
addTwistItem(new TwistItem(TwistVote.EXTRA_HEALTH, plugin.getCfg().extraHealthTwistConfig.getIcon()));
addTwistItem(new TwistItem(TwistVote.BLINDNESS, plugin.getCfg().blindnessTwistConfig.getIcon()));
addTwistItem(new TwistItem(TwistVote.RANDOM_YEET, plugin.getCfg().randomYeetTwistConfig.getIcon()));
addTwistItem(new TwistItem(TwistVote.SPEED_BOOST, plugin.getCfg().speedBoostTwistConfig.getIcon()));
addTwistItem(new TwistItem(TwistVote.GET_HIGH, plugin.getCfg().getHighTwistConfig.getIcon()));

IconConfig acidRainIcon = plugin.getCfg().acidRainTwistConfig.getIcon();
addTwistItem(new TwistItem(TwistVote.ACID_RAIN, acidRainIcon, item -> {
ItemMeta meta = item.getItemMeta();
if (item.getType() == Material.TIPPED_ARROW
|| item.getType() == Material.POTION
|| item.getType() == Material.SPLASH_POTION
|| item.getType() == Material.LINGERING_POTION) {
assert meta != null;
((PotionMeta) meta).setBasePotionData(new PotionData(PotionType.POISON));
}

assert meta != null;
meta.setDisplayName(Util.c(acidRainIcon.getDisplayName()));

meta.setLore(Objects.requireNonNull(item.getItemMeta()).getLore());
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);
}));

addTwistItem(new TwistItem(
TwistVote.NONE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.gaagjescraft.network.team.manhunt.menus.twist;

import me.gaagjescraft.network.team.manhunt.games.TwistVote;
import me.gaagjescraft.network.team.manhunt.utils.config.icon.IconConfig;
import org.bukkit.inventory.ItemStack;

import java.util.List;
Expand Down Expand Up @@ -29,6 +30,14 @@ public TwistItem(TwistVote vote, String icon, String displayName, List<String> l
this.customizer = (ignored) -> {};
}

public TwistItem(TwistVote vote, IconConfig icon) {
this(vote, icon.getMaterial(), icon.getDisplayName(), icon.getLore());
}

public TwistItem(TwistVote vote, IconConfig icon, Consumer<ItemStack> customizer) {
this(vote, icon.getMaterial(), icon.getDisplayName(), icon.getLore(), customizer);
}

public TwistVote getVote() {
return vote;
}
Expand Down
Loading