Skip to content

Commit

Permalink
Quality of live improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 5, 2024
1 parent 17a8234 commit e7e2c1f
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void onEnable() {
Console.sendMessage(CC.translate(" "));
Console.sendMessage(CC.translate("&7| &cPractice Core"));
Console.sendMessage(CC.translate(" "));
Console.sendMessage(CC.translate("&7| &fAutor(s): &c" + getInstance().getDescription().getAuthors().toString().replace("[", "").replace("]", "")));
Console.sendMessage(CC.translate("&7| &fAuthor(s): &c" + getInstance().getDescription().getAuthors().toString().replace("[", "").replace("]", "")));
Console.sendMessage(CC.translate("&7| &fVersion: &c" + getInstance().getDescription().getVersion()));
Console.sendMessage(CC.translate("&7| &fSpigot: &c" + getInstance().getServer().getName()));
Console.sendMessage(CC.translate(" "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void execute(Player player, String targetName) {
public void leave(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING && profile.getMatch().getGamePlayer(player).isDead()) {
if (profile.getMatch() != null && profile.getMatch().getGamePlayer(player).isDead()) {
profile.getMatch().getGamePlayer(player).setDisconnected(true);
profile.setState(ProfileState.LOBBY);
profile.setMatch(null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/kit/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void save() {
configFile.getConfiguration().set(path + ".game-rules.sumo", gameRules.isSumo());
configFile.getConfiguration().set(path + ".game-rules.bedwars", gameRules.isBedwars());
configFile.getConfiguration().set(path + ".game-rules.health-regeneration", gameRules.isHealthRegeneration());
configFile.getConfiguration().set(path + ".game-rules.hit-delay", gameRules.getHitDelay());
configFile.getConfiguration().set(path + ".game-rules.show-health", gameRules.isShowHealth());
configFile.getConfiguration().set(path + ".game-rules.hit-delay", gameRules.getHitDelay());
configFile.getConfiguration().set(path + ".game-rules.boxing", gameRules.isBoxing());

Expand Down
22 changes: 20 additions & 2 deletions src/main/java/me/lrxh/practice/kit/command/KitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.lrxh.practice.match.participant.MatchGamePlayer;
import me.lrxh.practice.participant.GameParticipant;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.ProfileState;
import me.lrxh.practice.util.CC;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -54,6 +53,7 @@ public void help2(Player player) {
player.sendMessage(CC.translate("&7* &c/kit setdescription &7<kit> &7<value> &7- &fSet kit description"));
player.sendMessage(CC.translate("&7* &c/kit build &7<kit> &7- &fAdd Build rule"));
player.sendMessage(CC.translate("&7* &c/kit spleef &7<kit> &7- &fAdd Spleef rule"));
player.sendMessage(CC.translate("&7* &c/kit showhp &7<kit> &7- &fAdd Shop HP rule"));
player.sendMessage(CC.translate("&7&m-----------------------------------------"));
}

Expand Down Expand Up @@ -340,6 +340,24 @@ public void hpregen(Player player, String kitName) {
player.sendMessage(CC.GREEN + "You updated the kit's health regeneration status to " + (kit.getGameRules().isShowHealth() ? "Enabled" : ChatColor.RED + "Disabled" + "."));
}

@Subcommand("showhp")
@CommandCompletion("@kits")
@Syntax("<kit>")
public void showhp(Player player, String kitName) {
if (!Kit.getKits().contains(Kit.getByName(kitName))) {
player.sendMessage(CC.translate("&4ERROR - &cKit doesn't exists!"));
return;
}
Kit kit = Kit.getByName(kitName);
if (kit == null) return;

kit.getGameRules().setShowHealth(!kit.getGameRules().isShowHealth());
kit.save();

player.sendMessage(CC.GREEN + "You updated the kit's show health status to " + (kit.getGameRules().isShowHealth() ? "Enabled" : ChatColor.RED + "Disabled" + "."));
}


@Subcommand("hitdelay")
@CommandCompletion("@kits")
@Syntax("<kit>")
Expand All @@ -353,7 +371,7 @@ public void showhp(Player player, String kitName, int delay) {

kit.getGameRules().setHitDelay(delay);
Profile profile = Profile.getByUuid(player.getUniqueId());
if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();
for (GameParticipant<MatchGamePlayer> gameParticipant : match.getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/me/lrxh/practice/kit/menu/KitEditorMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private static class ClearInventoryButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.STAINED_CLAY)
.durability(7)
return new ItemBuilder(Material.WOOL)
.durability(3)
.name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.CLEAR-BUTTON"))
.clearFlags()
.build();
Expand All @@ -178,8 +178,8 @@ private static class LoadDefaultKitButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.STAINED_CLAY)
.durability(7)
return new ItemBuilder(Material.WOOL)
.durability(4)
.name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.LOAD-DEFAULT-BUTTON"))
.clearFlags()
.build();
Expand Down Expand Up @@ -208,7 +208,7 @@ private static class SaveButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.STAINED_CLAY)
return new ItemBuilder(Material.WOOL)
.durability(5)
.name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.SAVE-BUTTON"))
.clearFlags()
Expand Down Expand Up @@ -240,7 +240,7 @@ private static class CancelButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.STAINED_CLAY)
return new ItemBuilder(Material.WOOL)
.durability(14)
.name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.CANCEL-BUTTON"))
.clearFlags()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static class DeleteKitButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.STAINED_CLAY)
return new ItemBuilder(Material.REDSTONE)
.name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.MANAGEMENT.BUTTONS.DELETE-BUTTON"))
.clearFlags()
.build();
Expand Down
39 changes: 14 additions & 25 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.bukkit.*;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -159,6 +159,11 @@ public void setupPlayer(Player player) {
// Reset the player's inventory
PlayerUtil.reset(player);

if (kit.getGameRules().isShowHealth()) {


}


// Set the player's max damage ticks
player.setMaximumNoDamageTicks(getKit().getGameRules().getHitDelay());
Expand Down Expand Up @@ -263,6 +268,11 @@ public void end() {
Practice.getInstance().getHotbar().giveHotbarItems(player);
PlayerUtil.teleportToSpawn(player);
PlayerUtil.allowMovement(gamePlayer.getPlayer());
Objective objective = player.getScoreboard().getObjective(DisplaySlot.BELOW_NAME);

if (objective != null) {
objective.unregister();
}
}
}
}
Expand Down Expand Up @@ -501,31 +511,10 @@ public void onDeath(Player dead) {

// Get killer
if (killer != null) {

Profile killerProfile = Profile.getByUuid(killer.getUniqueId());
Location location = dead.getLocation();
World world = location.getWorld();
switch (killerProfile.getOptions().killEffect()) {
case LIGHTNING:
double x = location.getX();
double y = location.getY() + 2.0;
double z = location.getZ();
Location lightningLocation = new Location(world, x, y, z);
world.strikeLightning(lightningLocation);
break;
case FIREWORKS:
Firework firework = world.spawn(location, Firework.class);
FireworkMeta meta = firework.getFireworkMeta();
FireworkEffect.Builder builder = FireworkEffect.builder()
.withColor(Color.RED)
.with(FireworkEffect.Type.BALL_LARGE)
.trail(true)
.flicker(false);
meta.addEffect(builder.build());
meta.setPower(1);
firework.setFireworkMeta(meta);
Bukkit.getScheduler().runTaskLater(Practice.getInstance(), firework::detonate, 5L);
break;
}
killerProfile.getOptions().killEffect().execute(killer, location);
PlayerUtil.setLastAttacker(killer, null);
killer.playSound(killer.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class MatchListener implements Listener {
public void onPlayerMoveEvent(PlayerMoveEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {

if (profile.getMatch() != null) {
if (profile.getMatch().getKit().getGameRules().isSumo() ||
profile.getMatch().getKit().getGameRules().isSpleef()) {
Match match = profile.getMatch();
Expand Down Expand Up @@ -103,7 +104,7 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) {
public void onBlockPlaceEvent(BlockPlaceEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();

if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) {
Expand Down Expand Up @@ -165,7 +166,7 @@ public void onFallDamageEvent(EntityDamageEvent event) {
public void onBlockBreakEvent(BlockBreakEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();
if (event.getBlock().getType() == Material.BED_BLOCK || event.getBlock().getType() == Material.BED) {
Player player = event.getPlayer();
Expand Down Expand Up @@ -235,7 +236,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
public void onBucketEmptyEvent(PlayerBucketEmptyEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();

if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) {
Expand Down Expand Up @@ -271,7 +272,7 @@ public void onBucketEmptyEvent(PlayerBucketEmptyEvent event) {
public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
if (profile.getMatch().getGamePlayer(event.getPlayer()).isDead()) {
event.setCancelled(true);
return;
Expand Down Expand Up @@ -312,7 +313,7 @@ public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
return;
}

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
if (event.getItemDrop().getItemStack().getType() == Material.GLASS_BOTTLE) {
event.getItemDrop().remove();
return;
Expand Down Expand Up @@ -347,7 +348,7 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {

Profile profile = Profile.getByUuid(event.getEntity().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {

Match match = profile.getMatch();
event.getDrops().clear();
Expand Down Expand Up @@ -386,7 +387,7 @@ public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
Player shooter = (Player) event.getEntity().getShooter();
Profile profile = Profile.getByUuid(shooter.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();

if (match.getState() == MatchState.STARTING_ROUND) {
Expand Down Expand Up @@ -443,7 +444,7 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
Profile profile = Profile.getByUuid(event.getEntity().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING && !profile.getMatch().getKit().getGameRules().isHealthRegeneration()) {
if (profile.getMatch() != null && !profile.getMatch().getKit().getGameRules().isHealthRegeneration()) {
event.setCancelled(true);
}
}
Expand All @@ -456,7 +457,7 @@ public void onEntityDamage(EntityDamageEvent event) {
Player player = (Player) event.getEntity();
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {

if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {

Expand Down Expand Up @@ -500,7 +501,7 @@ public void onEntityDamage(EntityDamageEvent event) {
public void onHungerChange(FoodLevelChangeEvent event) {
Player player = (Player) event.getEntity();
Profile profile = Profile.getByUuid(player.getUniqueId());
if (!profile.getState().equals(ProfileState.FIGHTING)) return;
if (profile.getMatch() == null) return;
if (profile.getMatch().getKit().getGameRules().isSumo()
|| profile.getMatch().getKit().getGameRules().isBedwars()
|| profile.getMatch().getKit().getGameRules().isSpleef()
Expand Down Expand Up @@ -628,7 +629,7 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) {
Player player = (Player) event.getEntity();
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING &&
if (profile.getMatch() != null &&
profile.getMatch().getState() == MatchState.PLAYING_ROUND) {
if (event.getFoodLevel() >= 20) {
event.setFoodLevel(20);
Expand All @@ -646,7 +647,7 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) {
// public void onPlayerQuitEvent(PlayerQuitEvent event) {
// Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId());
//
// if (profile.getState() == ProfileState.FIGHTING) {
// if (profile.getMatch() != null) {
// Match match = profile.getMatch();
//
// if (match != null && (match.getState() == MatchState.STARTING_ROUND || match.getState() == MatchState.PLAYING_ROUND)) {
Expand Down Expand Up @@ -710,7 +711,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();

if (Practice.getInstance().getHotbar().fromItemStack(itemStack) == HotbarItem.SPECTATE_STOP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void run() {
for (Player player : Practice.getInstance().getServer().getOnlinePlayers()) {
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getState() == ProfileState.FIGHTING || profile.getState() == ProfileState.EVENT) {
if (profile.getMatch() != null || profile.getState() == ProfileState.EVENT) {
if (profile.getEnderpearlCooldown().hasExpired()) {
if (!profile.getEnderpearlCooldown().isNotified()) {
profile.getEnderpearlCooldown().setNotified(true);
Expand Down
44 changes: 41 additions & 3 deletions src/main/java/me/lrxh/practice/profile/KillEffects.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
package me.lrxh.practice.profile;

import lombok.Getter;
import me.lrxh.practice.Practice;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;

@Getter
public enum KillEffects {
NONE("None"),
LIGHTNING("Lightning"),
FIREWORKS("Fireworks");
NONE("None") {
@Override
public void execute(Player player, Location location) {
}
},
LIGHTNING("Lightning") {
@Override
public void execute(Player player, Location location) {
double x = location.getX();
double y = location.getY() + 2.0;
double z = location.getZ();
Location lightningLocation = new Location(location.getWorld(), x, y, z);
location.getWorld().strikeLightning(lightningLocation);
}
},
FIREWORKS("Fireworks") {
@Override
public void execute(Player player, Location location) {
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta meta = firework.getFireworkMeta();
FireworkEffect.Builder builder = FireworkEffect.builder()
.withColor(Color.RED)
.with(FireworkEffect.Type.BALL_LARGE)
.trail(true)
.flicker(false);
meta.addEffect(builder.build());
meta.setPower(1);
firework.setFireworkMeta(meta);
Bukkit.getScheduler().runTaskLater(Practice.getInstance(), firework::detonate, 5L);
}
};

private final String displayName;

KillEffects(String displayName) {
this.displayName = displayName;
}

public abstract void execute(Player player, Location location);
}
Loading

0 comments on commit e7e2c1f

Please sign in to comment.