Compare commits
2 Commits
a534173686
...
8b3f7a0980
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b3f7a0980 | |||
| eecb2bb04c |
@@ -6,7 +6,9 @@ import com.hypixel.hytale.logger.HytaleLogger;
|
|||||||
import com.hypixel.hytale.server.core.HytaleServer;
|
import com.hypixel.hytale.server.core.HytaleServer;
|
||||||
import com.hypixel.hytale.server.core.Message;
|
import com.hypixel.hytale.server.core.Message;
|
||||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||||
|
import com.hypixel.hytale.server.core.inventory.Inventory;
|
||||||
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
import com.hypixel.hytale.server.core.inventory.ItemStack;
|
||||||
|
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
|
||||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||||
import com.hypixel.hytale.server.core.universe.Universe;
|
import com.hypixel.hytale.server.core.universe.Universe;
|
||||||
import com.hypixel.hytale.server.core.universe.world.World;
|
import com.hypixel.hytale.server.core.universe.world.World;
|
||||||
@@ -76,6 +78,7 @@ public final class KothService {
|
|||||||
tickTask = null;
|
tickTask = null;
|
||||||
}
|
}
|
||||||
for (ArenaPlayer ap : arenaPlayers.values()) {
|
for (ArenaPlayer ap : arenaPlayers.values()) {
|
||||||
|
removeSword(ap.playerRef);
|
||||||
safeOnWorld(ap.playerRef, () -> ap.hud.clear());
|
safeOnWorld(ap.playerRef, () -> ap.hud.clear());
|
||||||
}
|
}
|
||||||
arenaPlayers.clear();
|
arenaPlayers.clear();
|
||||||
@@ -115,6 +118,8 @@ public final class KothService {
|
|||||||
accumulatedMs.computeIfAbsent(uuid, k -> 0L);
|
accumulatedMs.computeIfAbsent(uuid, k -> 0L);
|
||||||
giveSword(playerRef);
|
giveSword(playerRef);
|
||||||
if (hudVisibility != null) hudVisibility.showAll(playerRef);
|
if (hudVisibility != null) hudVisibility.showAll(playerRef);
|
||||||
|
} else {
|
||||||
|
removeSword(playerRef);
|
||||||
}
|
}
|
||||||
ap.hud.render(buildSnapshot(uuid, computeRanking()));
|
ap.hud.render(buildSnapshot(uuid, computeRanking()));
|
||||||
}
|
}
|
||||||
@@ -123,7 +128,7 @@ public final class KothService {
|
|||||||
UUID uuid = playerRef.getUuid();
|
UUID uuid = playerRef.getUuid();
|
||||||
ArenaPlayer removed = arenaPlayers.remove(uuid);
|
ArenaPlayer removed = arenaPlayers.remove(uuid);
|
||||||
if (removed != null) removed.hud.clear();
|
if (removed != null) removed.hud.clear();
|
||||||
if (phase == Phase.ACTIVE) removeSword(playerRef);
|
removeSword(playerRef);
|
||||||
if (hudVisibility != null) hudVisibility.applyHidden(playerRef);
|
if (hudVisibility != null) hudVisibility.applyHidden(playerRef);
|
||||||
currentCapturers.remove(uuid);
|
currentCapturers.remove(uuid);
|
||||||
}
|
}
|
||||||
@@ -337,13 +342,36 @@ public final class KothService {
|
|||||||
|
|
||||||
private void giveSword(@Nonnull PlayerRef ref) {
|
private void giveSword(@Nonnull PlayerRef ref) {
|
||||||
short slot = (short) Math.max(0, cfg.sword_slot);
|
short slot = (short) Math.max(0, cfg.sword_slot);
|
||||||
runOnPlayerEntity(ref, player ->
|
runOnPlayerEntity(ref, player -> {
|
||||||
player.getInventory().getHotbar().addItemStackToSlot(slot, new ItemStack(cfg.sword_item_id, 1)));
|
player.getInventory().getHotbar().addItemStackToSlot(slot, new ItemStack(cfg.sword_item_id, 1));
|
||||||
|
player.markNeedsSave();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeSword(@Nonnull PlayerRef ref) {
|
private void removeSword(@Nonnull PlayerRef ref) {
|
||||||
runOnPlayerEntity(ref, player ->
|
runOnPlayerEntity(ref, player -> {
|
||||||
player.getInventory().getHotbar().removeItemStack(new ItemStack(cfg.sword_item_id, 1)));
|
Inventory inventory = player.getInventory();
|
||||||
|
boolean removed = false;
|
||||||
|
removed |= removeSwordFrom(inventory.getHotbar());
|
||||||
|
removed |= removeSwordFrom(inventory.getStorage());
|
||||||
|
removed |= removeSwordFrom(inventory.getBackpack());
|
||||||
|
removed |= removeSwordFrom(inventory.getUtility());
|
||||||
|
removed |= removeSwordFrom(inventory.getTools());
|
||||||
|
if (removed) player.markNeedsSave();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeSwordFrom(@Nullable ItemContainer container) {
|
||||||
|
if (container == null) return false;
|
||||||
|
final boolean[] removed = {false};
|
||||||
|
container.replaceAll((slot, stack) -> {
|
||||||
|
if (!ItemStack.isEmpty(stack) && cfg.sword_item_id.equals(stack.getItemId())) {
|
||||||
|
removed[0] = true;
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
});
|
||||||
|
return removed[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runOnPlayerEntity(@Nonnull PlayerRef ref,
|
private void runOnPlayerEntity(@Nonnull PlayerRef ref,
|
||||||
|
|||||||
Reference in New Issue
Block a user