Skip to content

Commit

Permalink
Merge pull request #10 from StaffV77/main
Browse files Browse the repository at this point in the history
new changes
  • Loading branch information
Sstudiosdev authored Mar 31, 2024
2 parents 21b4379 + ecb474f commit 74fed1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.sstudiosdev.listener;

import io.github.sstudiosdev.BetterPvP;
import io.github.sstudiosdev.util.ChatColorUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -14,7 +17,14 @@
import java.util.Set;

public class RespawnProtectionListener implements Listener {
private Set<Player> playersWithRespawnProtection = new HashSet<>();
private final Set<Player> playersWithRespawnProtection = new HashSet<>();
private final JavaPlugin plugin;
private final FileConfiguration config;

public RespawnProtectionListener(JavaPlugin plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
}

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Expand All @@ -28,10 +38,11 @@ public void onPlayerDeath(PlayerDeathEvent event) {
public void onPlayerRespawn(PlayerRespawnEvent event) {
final Player player = event.getPlayer();
playersWithRespawnProtection.add(player);
Bukkit.getScheduler().runTaskLater((JavaPlugin) Bukkit.getPluginManager().getPlugin("BetterPvP"), () -> {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
playersWithRespawnProtection.remove(player);
player.sendMessage(ChatColor.GREEN + "¡Has terminado la protección de respawn!");
}, 100); // 5 segundos (20 ticks por segundo, 100 ticks = 5 segundos)
String respawnMessage = ChatColorUtil.colorize(BetterPvP.prefix + " " + config.getString("respawn_message"));
player.sendMessage(respawnMessage);
}, 100); // 5 seconds (20 ticks per second, 100 ticks = 5 seconds)
}

@EventHandler
Expand All @@ -40,8 +51,9 @@ public void onEntityDamage(EntityDamageEvent event) {
Player player = (Player) event.getEntity();
if (playersWithRespawnProtection.contains(player)) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "¡No puedes recibir daño mientras tienes protección de respawn!");
String protectionMessage = ChatColorUtil.colorize(BetterPvP.prefix + " " + config.getString("protection_message"));
player.sendMessage(protectionMessage);
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pvptoggle: "&aPvP is now %status%."
pvpworld-enabled: "&aPvP combat has been activated in the world %world%."
pvpworld-disabled: "&cPvP combat has been disabled in the world %world%."
cooldown-error-message: "&cYou must wait before using this command again."
respawn_message: "&aYou have finished respawn protection!"
protection_message: "&cYou cannot take damage while you have respawn protection!"

# ============================================================
# | AntiKillAbuse |
Expand Down

0 comments on commit 74fed1c

Please sign in to comment.