13
0

Add long right click compass to reset
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-11-15 17:36:29 +01:00
Ursprung 6f5d739012
Commit 3f792cb367
2 geänderte Dateien mit 56 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -84,5 +84,6 @@ PARTICLE_EVENT_WGS = §fWGS
PARTICLE_EVENT_WARGEARCLASH = §fClash PARTICLE_EVENT_WARGEARCLASH = §fClash
JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §c{2} §7{3} JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §c{2} §7{3}
JUMP_AND_RUN_CANCEL = {0}
JUMP_AND_RUN_TIME = mm:ss SSS JUMP_AND_RUN_TIME = mm:ss SSS
JUMP_AND_RUN_FINISHED = §aFinished in {0} with {1} fails JUMP_AND_RUN_FINISHED = §aFinished in {0} with {1} fails

Datei anzeigen

@ -10,6 +10,8 @@ import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -20,15 +22,27 @@ import java.util.*;
public class JumpAndRun extends BasicListener { public class JumpAndRun extends BasicListener {
private static final String BAR_EMPTY = "||||||||||||||||||||||||||||||";
public static List<Vector> points = new ArrayList<>(); public static List<Vector> points = new ArrayList<>();
private static final Map<Player, Integer> CURRENT_POS = new HashMap<>(); private static final Map<Player, Integer> CURRENT_POS = new HashMap<>();
private static final Map<Player, Integer> FAILS = new HashMap<>(); private static final Map<Player, Integer> FAILS = new HashMap<>();
private static final Map<Player, Long> START = new HashMap<>(); private static final Map<Player, Long> START = new HashMap<>();
private static final Map<Player, Long> CLICKED = new HashMap<>();
private static final Map<Player, Integer> CLICKED_COUNT = new HashMap<>();
static { {
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> {
Set<Player> toReset = new HashSet<>();
CURRENT_POS.forEach((player, index) -> { CURRENT_POS.forEach((player, index) -> {
if (System.currentTimeMillis() - CLICKED.getOrDefault(player, 0L) > 500) {
CLICKED.remove(player);
CLICKED_COUNT.remove(player);
} else {
CLICKED_COUNT.put(player, CLICKED_COUNT.getOrDefault(player, -1) + 1);
}
Location location = player.getLocation(); Location location = player.getLocation();
Vector point = points.get(index); Vector point = points.get(index);
if (index < points.size() - 1) { if (index < points.size() - 1) {
@ -44,10 +58,24 @@ public class JumpAndRun extends BasicListener {
} }
} }
int count = CLICKED_COUNT.getOrDefault(player, -1);
if (count >= 0) {
if (count > 60) {
toReset.add(player);
return;
}
count = Math.min(count / 2, 30);
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_CANCEL", player, ChatMessageType.ACTION_BAR, "§e" + BAR_EMPTY.substring(0, count) + "§7" + BAR_EMPTY.substring(count));
} else {
long time = System.currentTimeMillis() - START.get(player); long time = System.currentTimeMillis() - START.get(player);
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT); SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
String parsed = format.format(new Date(time)); String parsed = format.format(new Date(time));
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed.substring(0, parsed.length() - 2)); LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed.substring(0, parsed.length() - 2));
}
});
toReset.forEach(player -> {
reset(player);
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5));
}); });
}, 1, 1); }, 1, 1);
} }
@ -93,11 +121,7 @@ public class JumpAndRun extends BasicListener {
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", event.getPlayer()), Locale.ROOT); SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", event.getPlayer()), Locale.ROOT);
String parsed = format.format(new Date(time)); String parsed = format.format(new Date(time));
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed.substring(0, parsed.length() - 2), FAILS.get(event.getPlayer())); LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed.substring(0, parsed.length() - 2), FAILS.get(event.getPlayer()));
PlayerSpawn.giveItems(event.getPlayer()); reset(event.getPlayer());
event.getPlayer().setAllowFlight(true);
CURRENT_POS.remove(event.getPlayer());
START.remove(event.getPlayer());
FAILS.remove(event.getPlayer());
} }
} }
@ -107,5 +131,26 @@ public class JumpAndRun extends BasicListener {
CURRENT_POS.remove(player); CURRENT_POS.remove(player);
START.remove(player); START.remove(player);
FAILS.remove(player); FAILS.remove(player);
CLICKED.remove(event.getPlayer());
CLICKED_COUNT.remove(event.getPlayer());
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getItem() == null) return;
if (event.getItem().getType() != Material.COMPASS) return;
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
event.setCancelled(true);
CLICKED.put(event.getPlayer(), System.currentTimeMillis());
}
private void reset(Player player) {
PlayerSpawn.giveItems(player);
player.setAllowFlight(true);
CURRENT_POS.remove(player);
START.remove(player);
FAILS.remove(player);
CLICKED.remove(player);
CLICKED_COUNT.remove(player);
} }
} }