Dieser Commit ist enthalten in:
Ursprung
6f5d739012
Commit
3f792cb367
@ -84,5 +84,6 @@ PARTICLE_EVENT_WGS = §fWGS
|
||||
PARTICLE_EVENT_WARGEARCLASH = §fClash
|
||||
|
||||
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_FINISHED = §aFinished in {0} with {1} fails
|
@ -10,6 +10,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
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.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -20,15 +22,27 @@ import java.util.*;
|
||||
|
||||
public class JumpAndRun extends BasicListener {
|
||||
|
||||
private static final String BAR_EMPTY = "||||||||||||||||||||||||||||||";
|
||||
|
||||
public static List<Vector> points = new ArrayList<>();
|
||||
|
||||
private static final Map<Player, Integer> CURRENT_POS = 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> CLICKED = new HashMap<>();
|
||||
private static final Map<Player, Integer> CLICKED_COUNT = new HashMap<>();
|
||||
|
||||
static {
|
||||
{
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> {
|
||||
Set<Player> toReset = new HashSet<>();
|
||||
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();
|
||||
Vector point = points.get(index);
|
||||
if (index < points.size() - 1) {
|
||||
@ -44,10 +58,24 @@ public class JumpAndRun extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis() - START.get(player);
|
||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
||||
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));
|
||||
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);
|
||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
||||
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));
|
||||
}
|
||||
});
|
||||
toReset.forEach(player -> {
|
||||
reset(player);
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5));
|
||||
});
|
||||
}, 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);
|
||||
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()));
|
||||
PlayerSpawn.giveItems(event.getPlayer());
|
||||
event.getPlayer().setAllowFlight(true);
|
||||
CURRENT_POS.remove(event.getPlayer());
|
||||
START.remove(event.getPlayer());
|
||||
FAILS.remove(event.getPlayer());
|
||||
reset(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,5 +131,26 @@ public class JumpAndRun extends BasicListener {
|
||||
CURRENT_POS.remove(player);
|
||||
START.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);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren