-
Notifications
You must be signed in to change notification settings - Fork 29
Ajout d'un cooldown de téléportation lors d'un combat #1340
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,7 +115,9 @@ private boolean isSafe(Location loc) { | |||||||||
| } | ||||||||||
|
|
||||||||||
| private void tpPlayer(Player player, Location loc) { | ||||||||||
| PlayerUtils.sendFadeTitleTeleport(player, loc); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(player, loc)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+118
to
+120
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| MessagesManager.sendMessage(player, TranslationManager.translation("command.utils.rtp.success", | ||||||||||
| Component.text(loc.getBlockX()).color(YELLOW), | ||||||||||
| Component.text(loc.getBlockY()).color(YELLOW), | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,11 @@ | |||||||||
| import org.bukkit.Location; | ||||||||||
| import org.bukkit.command.CommandSender; | ||||||||||
| import org.bukkit.entity.Player; | ||||||||||
| import revxrsal.commands.annotation.*; | ||||||||||
| import revxrsal.commands.annotation.Command; | ||||||||||
| import revxrsal.commands.annotation.Description; | ||||||||||
| import revxrsal.commands.annotation.Named; | ||||||||||
| import revxrsal.commands.annotation.Optional; | ||||||||||
| import revxrsal.commands.annotation.SuggestWith; | ||||||||||
| import revxrsal.commands.bukkit.annotation.CommandPermission; | ||||||||||
|
|
||||||||||
| public class Spawn { | ||||||||||
|
|
@@ -27,12 +31,16 @@ public void spawn( | |||||||||
| Location spawnLocation = SpawnManager.getSpawnLocation(); | ||||||||||
|
|
||||||||||
| if (sender instanceof Player player && (target == null || player.getUniqueId().equals(target.getUniqueId()))) { | ||||||||||
| PlayerUtils.sendFadeTitleTeleport(player, spawnLocation); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(player, spawnLocation)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+34
to
+36
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| MessagesManager.sendMessage(player, TranslationManager.translation("command.utils.spawn.got_sent"), | ||||||||||
| Prefix.OPENMC, MessageType.SUCCESS, true); | ||||||||||
| } else { | ||||||||||
| if(!(sender instanceof Player) || sender.hasPermission("omc.admin.commands.spawn.others")) { | ||||||||||
| PlayerUtils.sendFadeTitleTeleport(target, spawnLocation); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(target, spawnLocation)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+41
to
+43
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| MessagesManager.sendMessage(sender, TranslationManager.translation("command.utils.spawn.have_sent", | ||||||||||
| Component.text(target.getName()).color(NamedTextColor.YELLOW)), Prefix.OPENMC, MessageType.SUCCESS, true); | ||||||||||
| MessagesManager.sendMessage(target, TranslationManager.translation("command.utils.spawn.have_sent_by", | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||
| package fr.openmc.core.features.combat; | ||||||||||
|
|
||||||||||
| import org.bukkit.entity.Player; | ||||||||||
| import org.bukkit.event.EventHandler; | ||||||||||
| import org.bukkit.event.EventPriority; | ||||||||||
| import org.bukkit.event.Listener; | ||||||||||
| import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||||||||||
| import org.bukkit.event.player.PlayerQuitEvent; | ||||||||||
|
|
||||||||||
| public final class CombatCooldownListener implements Listener { | ||||||||||
|
|
||||||||||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||||||
| public void onPlayerHit(EntityDamageByEntityEvent event) { | ||||||||||
| if (!(event.getEntity() instanceof Player player)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+14
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| if (!(event.getDamager() instanceof Player)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+18
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| if (event.getFinalDamage() <= 0) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+22
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| CombatCooldownManager.recordHit(player.getUniqueId()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @EventHandler | ||||||||||
| public void onPlayerQuit(PlayerQuitEvent event) { | ||||||||||
| CombatCooldownManager.clear(event.getPlayer().getUniqueId()); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||
| package fr.openmc.core.features.combat; | ||||||||||
|
|
||||||||||
| import java.time.Duration; | ||||||||||
| import java.util.UUID; | ||||||||||
| import java.util.concurrent.ConcurrentHashMap; | ||||||||||
|
|
||||||||||
| public final class CombatCooldownManager { | ||||||||||
|
|
||||||||||
| private static final long COMBAT_COOLDOWN_MILLIS = Duration.ofSeconds(10).toMillis(); | ||||||||||
| private static final ConcurrentHashMap<UUID, Long> LAST_HIT_TIMES = new ConcurrentHashMap<>(); | ||||||||||
|
|
||||||||||
| private CombatCooldownManager() { | ||||||||||
| } | ||||||||||
|
Comment on lines
+12
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| public static void recordHit(UUID playerId) { | ||||||||||
| LAST_HIT_TIMES.put(playerId, System.currentTimeMillis()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static long getRemainingSeconds(UUID playerId) { | ||||||||||
| Long lastHitTime = LAST_HIT_TIMES.get(playerId); | ||||||||||
| if (lastHitTime == null) { | ||||||||||
| return 0; | ||||||||||
| } | ||||||||||
|
Comment on lines
+21
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| long remainingMillis = lastHitTime + COMBAT_COOLDOWN_MILLIS - System.currentTimeMillis(); | ||||||||||
| if (remainingMillis <= 0) { | ||||||||||
| LAST_HIT_TIMES.remove(playerId, lastHitTime); | ||||||||||
| return 0; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return Math.ceilDiv(remainingMillis, 1000L); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explique moi c'est quoi ça |
||||||||||
| } | ||||||||||
|
|
||||||||||
| public static void clear(UUID playerId) { | ||||||||||
| LAST_HIT_TIMES.remove(playerId); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,11 @@ | |||||||||
| import org.bukkit.OfflinePlayer; | ||||||||||
| import org.bukkit.entity.Player; | ||||||||||
| import org.bukkit.scheduler.BukkitRunnable; | ||||||||||
| import revxrsal.commands.annotation.*; | ||||||||||
| import revxrsal.commands.annotation.Command; | ||||||||||
| import revxrsal.commands.annotation.Description; | ||||||||||
| import revxrsal.commands.annotation.Named; | ||||||||||
| import revxrsal.commands.annotation.Optional; | ||||||||||
| import revxrsal.commands.annotation.SuggestWith; | ||||||||||
| import revxrsal.commands.bukkit.annotation.CommandPermission; | ||||||||||
|
|
||||||||||
| import java.util.List; | ||||||||||
|
|
@@ -59,7 +63,9 @@ public static void home( | |||||||||
|
|
||||||||||
| for(Home h : homes) { | ||||||||||
| if (h.getName().equalsIgnoreCase(split[1])) { | ||||||||||
| PlayerUtils.sendFadeTitleTeleport(player, h.getLocation()); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(player, h.getLocation())) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+66
to
+68
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| new BukkitRunnable() { | ||||||||||
| @Override | ||||||||||
| public void run() { | ||||||||||
|
|
@@ -100,7 +106,9 @@ public void run() { | |||||||||
|
|
||||||||||
| for(Home h : homes) { | ||||||||||
| if(h.getName().equalsIgnoreCase(home)) { | ||||||||||
| PlayerUtils.sendFadeTitleTeleport(player, h.getLocation()); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(player, h.getLocation())) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+109
to
+111
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| new BukkitRunnable() { | ||||||||||
| @Override | ||||||||||
| public void run() { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||
| import fr.openmc.core.features.homes.icons.HomeIcon; | ||||||||||
| import fr.openmc.core.features.homes.icons.HomeIconRegistry; | ||||||||||
| import fr.openmc.core.features.homes.models.Home; | ||||||||||
| import fr.openmc.core.utils.bukkit.PlayerUtils; | ||||||||||
| import fr.openmc.core.utils.text.messages.MessageType; | ||||||||||
| import fr.openmc.core.utils.text.messages.MessagesManager; | ||||||||||
| import fr.openmc.core.utils.text.messages.Prefix; | ||||||||||
|
|
@@ -107,24 +108,25 @@ public List<ItemStack> getItems() { | |||||||||
| }).hide(ItemUtils.getDataComponentType()).setOnClick(event -> { | ||||||||||
| if(event.isLeftClick()) { | ||||||||||
| this.getInventory().close(); | ||||||||||
| getOwner().teleportAsync(home.getLocation()).thenAccept(success -> { | ||||||||||
| new BukkitRunnable() { | ||||||||||
| @Override | ||||||||||
| public void run() { | ||||||||||
| Bukkit.getPluginManager().callEvent(new HomeTpEvent(home, getOwner())); | ||||||||||
| } | ||||||||||
| }.runTask(OMCPlugin.getInstance()); | ||||||||||
| MessagesManager.sendMessage( | ||||||||||
| getOwner(), | ||||||||||
| TranslationManager.translation( | ||||||||||
| "feature.homes.menu.teleport.success", | ||||||||||
| Component.text(home.getName()).color(NamedTextColor.YELLOW) | ||||||||||
| ), | ||||||||||
| Prefix.HOME, | ||||||||||
| MessageType.SUCCESS, | ||||||||||
| true | ||||||||||
| ); | ||||||||||
| }); | ||||||||||
| if (!PlayerUtils.sendFadeTitleTeleport(getOwner(), home.getLocation())) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+111
to
+113
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| new BukkitRunnable() { | ||||||||||
| @Override | ||||||||||
| public void run() { | ||||||||||
| Bukkit.getPluginManager().callEvent(new HomeTpEvent(home, getOwner())); | ||||||||||
| } | ||||||||||
| }.runTask(OMCPlugin.getInstance()); | ||||||||||
| MessagesManager.sendMessage( | ||||||||||
| getOwner(), | ||||||||||
| TranslationManager.translation( | ||||||||||
| "feature.homes.menu.teleport.success", | ||||||||||
| Component.text(home.getName()).color(NamedTextColor.YELLOW) | ||||||||||
| ), | ||||||||||
| Prefix.HOME, | ||||||||||
| MessageType.SUCCESS, | ||||||||||
| true | ||||||||||
| ); | ||||||||||
| } else if(event.isRightClick()) { | ||||||||||
| Player player = (Player) event.getWhoClicked(); | ||||||||||
| new HomeConfigMenu(player, home).open(); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finalement enleve ça c'est dégeu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fait toi une task personnelle