forked from SteamWar/SteamWar
Further simplification
This commit is contained in:
+18
-9
@@ -79,6 +79,10 @@ public class SimulatorCursor implements Listener {
|
|||||||
return ItemUtils.isItem(itemStack, "simulator");
|
return ItemUtils.isItem(itemStack, "simulator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasSimulatorItem(Player player) {
|
||||||
|
return isSimulatorItem(player.getInventory().getItemInMainHand()) || isSimulatorItem(player.getInventory().getItemInOffHand());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
@@ -121,7 +125,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||||
if (!event.isSneaking()) return;
|
if (!event.isSneaking()) return;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
if (!hasSimulatorItem(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LAST_SNEAKS.containsKey(player)) {
|
if (LAST_SNEAKS.containsKey(player)) {
|
||||||
@@ -147,7 +151,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void calcCursor(Player player) {
|
public static void calcCursor(Player player) {
|
||||||
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
if (!Permission.BUILD.hasPermission(player) || !hasSimulatorItem(player)) {
|
||||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||||
SWUtils.sendToActionbar(player, "");
|
SWUtils.sendToActionbar(player, "");
|
||||||
}
|
}
|
||||||
@@ -163,12 +167,17 @@ public class SimulatorCursor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SimulatorWatcher.show(simulator, player);
|
SimulatorWatcher.show(simulator, player);
|
||||||
|
Cursor cursor = getOrCreateCursor(player, simulator, cursorType.getOrDefault(player, CursorType.TNT));
|
||||||
|
cursor.renderDeduplicated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Cursor getOrCreateCursor(Player player, Simulator simulator, CursorType type) {
|
||||||
REntityServer targetServer = simulator == null ? emptyTargetServers.computeIfAbsent(player, __ -> new REntityServer()) : SimulatorWatcher.getEntityServerOfSimulator(simulator);
|
REntityServer targetServer = simulator == null ? emptyTargetServers.computeIfAbsent(player, __ -> new REntityServer()) : SimulatorWatcher.getEntityServerOfSimulator(simulator);
|
||||||
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
Optional<Cursor> currentCursor = swPlayer.getComponent(Cursor.class);
|
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||||
Cursor cursor;
|
|
||||||
if (currentCursor.isEmpty() || currentCursor.get().getTargetServer() != targetServer) {
|
Cursor cursor = activeCursor.orElse(null);
|
||||||
|
if (cursor == null || cursor.getTargetServer() != targetServer) {
|
||||||
swPlayer.removeComponent(Cursor.class);
|
swPlayer.removeComponent(Cursor.class);
|
||||||
cursor = new Cursor(
|
cursor = new Cursor(
|
||||||
targetServer,
|
targetServer,
|
||||||
@@ -180,11 +189,11 @@ public class SimulatorCursor implements Listener {
|
|||||||
(location, hitEntity) -> sendCursorActionbar(player, SimulatorStorage.getSimulator(player), location != null, hitEntity.isPresent())
|
(location, hitEntity) -> sendCursorActionbar(player, SimulatorStorage.getSimulator(player), location != null, hitEntity.isPresent())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
cursor = currentCursor.get();
|
|
||||||
cursor.setCursorMaterial(type.material);
|
cursor.setCursorMaterial(type.material);
|
||||||
cursor.setAllowedCursorModes(type.cursorModes);
|
cursor.setAllowedCursorModes(type.cursorModes);
|
||||||
}
|
}
|
||||||
cursor.renderDeduplicated();
|
|
||||||
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized boolean removeCursor(Player player) {
|
private static synchronized boolean removeCursor(Player player) {
|
||||||
@@ -226,7 +235,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
|
|
||||||
private static void handlePlayerClick(Player player, Location cursorLocation, Optional<REntity> hitEntity, Action action) {
|
private static void handlePlayerClick(Player player, Location cursorLocation, Optional<REntity> hitEntity, Action action) {
|
||||||
if (!Permission.BUILD.hasPermission(player)) return;
|
if (!Permission.BUILD.hasPermission(player)) return;
|
||||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
if (!hasSimulatorItem(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user