Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ You really need to call GameSabotageDeactivateEvent when it's done.

## Alte recomandari
- decrease player tracking range
- command to kill invisible armor_stands (holograms) on your maps during setup session `/kill @e[type=armor_stand,nbt={Invisible:1b}]`

23 changes: 19 additions & 4 deletions stevesus-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

<artifactId>stevesus-api</artifactId>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
Expand Down Expand Up @@ -40,13 +47,21 @@
<version>1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Hologram API -->
<!-- Some hologram Lib -->
<dependency>
<groupId>com.github.unldenis.holoeasy</groupId>
<artifactId>holoeasy-core</artifactId>
<version>4.3.2</version>
</dependency>
<!-- End Some Hologram Lib -->
<!-- Packet events -->
<dependency>
<groupId>com.andrei1058.hologramapi</groupId>
<artifactId>hologram-api</artifactId>
<version>[1.0-SNAPSHOT,)</version>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-spigot</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
<!-- End Packet events -->
<!-- Particle API -->
<dependency>
<groupId>com.andrei1058.spigot.versionsupport</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.andrei1058.stevesus.api.arena;

import com.andrei1058.hologramapi.Hologram;
import com.andrei1058.stevesus.api.hook.hologram.HologramI;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -37,7 +37,7 @@ public interface PlayerCorpse {
/**
* Get hologram to hide/ show it when necessary.
*/
@Nullable Hologram getHologram();
@Nullable HologramI getHologram();

/**
* Check if the given location is in corpse's range.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.andrei1058.stevesus.api.arena.meeting;

import com.andrei1058.hologramapi.Hologram;
import com.andrei1058.hologramapi.HologramPage;
import com.andrei1058.hologramapi.content.LineTextContent;
import com.andrei1058.stevesus.api.SteveSusAPI;
import com.andrei1058.stevesus.api.arena.Arena;
import com.andrei1058.stevesus.api.arena.team.Team;
import com.andrei1058.stevesus.api.hook.hologram.HologramI;
import com.andrei1058.stevesus.api.hook.hologram.HologramManager;
import com.andrei1058.stevesus.api.locale.Message;
import com.andrei1058.stevesus.common.api.arena.GameState;
import com.andrei1058.stevesus.common.gui.ItemUtil;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

Expand All @@ -28,39 +28,50 @@ public class MeetingButton {
// use this to identify armor stand entity
public static final String MEETING_BUTTON_META_DATA_KEY = "mbtnss";

private final Hologram buttonHologram;
private @Nullable HologramI buttonHologram = null;
private long lastUsage;
private final List<Location> particleLocations;
private List<Location> particleLocations = new ArrayList<>();
private int currentEntry = -1;
private UUID lastRequester;

public MeetingButton(Plugin plugin, Location location, Arena arena) {
location.setX(location.getBlockX() + 0.5);
location.setZ(location.getBlockZ() + 0.5);
ArmorStand buttonKeeper = location.getWorld().spawn(location.clone().subtract(0, 1.5, 0), ArmorStand.class);
ArmorStand buttonKeeper = location.getWorld().spawn(
location.clone().subtract(0, 1.5, 0), ArmorStand.class
);
buttonKeeper.setRemoveWhenFarAway(false);
buttonKeeper.setVisible(false);
buttonKeeper.setGravity(false);
ItemStack meetingHead = ItemUtil.createSkullWithSkin("https://textures.minecraft.net/texture/c73fb2a28f3b665486412db7b66cdb7fc5c7d33d74e850b94722dd3d14aaa", "Emergency Meeting");
buttonKeeper.setHelmet(meetingHead);
buttonKeeper.setMetadata(MEETING_BUTTON_META_DATA_KEY, new FixedMetadataValue(plugin, arena.getGameId()));

buttonHologram = new Hologram(location.clone().add(0, 1.5, 0), 3);
HologramPage page = buttonHologram.getPage(0);
assert page != null;
page.setLineContent(0, new LineTextContent(s -> SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.EMERGENCY_BUTTON_HOLO1)));
page.setLineContent(1, new LineTextContent(s -> arena.getMeetingStage() == MeetingStage.NO_MEETING ? SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.EMERGENCY_BUTTON_HOLO2) : " "));
page.setLineContent(2, new LineTextContent(s -> {
if (arena.getMeetingStage() == MeetingStage.TALKING) {
return SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.EMERGENCY_BUTTON_STATUS_VOTING_STARTS_IN).replace("{time}", String.valueOf(arena.getCountdown()));
} else if (arena.getMeetingStage() == MeetingStage.VOTING) {
return SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.EMERGENCY_BUTTON_STATUS_VOTING_ENDS_IN).replace("{time}", String.valueOf(arena.getCountdown()));
}
return SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.EMERGENCY_BUTTON_STATUS_YOUR_MEETINGS_LEFT).replace("{amount}", String.valueOf(arena.getMeetingsLeft(s)));
}));
if (null != HologramManager.getInstance().getProvider()) {
buttonHologram = HologramManager.getInstance().getProvider().spawnHologram(location);

var localeHandler = SteveSusAPI.getInstance().getLocaleHandler();
buttonHologram.setPageContent(Arrays.asList(
receiver -> localeHandler.getMsg(receiver, Message.EMERGENCY_BUTTON_HOLO1),
receiver -> arena.getMeetingStage() == MeetingStage.NO_MEETING ?
localeHandler.getMsg(receiver, Message.EMERGENCY_BUTTON_HOLO2) :
" ",
receiver -> {
if (arena.getMeetingStage() == MeetingStage.TALKING) {
return localeHandler.getMsg(receiver, Message.EMERGENCY_BUTTON_STATUS_VOTING_STARTS_IN)
.replace("{time}", String.valueOf(arena.getCountdown()));
} else if (arena.getMeetingStage() == MeetingStage.VOTING) {
return localeHandler.getMsg(receiver, Message.EMERGENCY_BUTTON_STATUS_VOTING_ENDS_IN)
.replace("{time}", String.valueOf(arena.getCountdown()));
}
return localeHandler.getMsg(receiver, Message.EMERGENCY_BUTTON_STATUS_YOUR_MEETINGS_LEFT)
.replace("{amount}", String.valueOf(arena.getMeetingsLeft(receiver)));
}
));
buttonHologram.hideToAll();
}

this.particleLocations = getCircle(location.clone().add(0, 0.3, 0), 0.6, 15);
buttonHologram.hide();
}

/**
Expand All @@ -77,8 +88,15 @@ public void refreshLines(Arena arena) {
}
}

public void onGameStart() {
buttonHologram.show();
public void onGameStart(Arena arena) {
if (null != buttonHologram && null != arena) {
arena.getPlayers().forEach(
player -> buttonHologram.showToPlayer(player)
);
arena.getSpectators().forEach(
spectator -> buttonHologram.showToPlayer(spectator)
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,65 @@
package com.andrei1058.stevesus.api.arena.securitycamera;

import com.andrei1058.hologramapi.Hologram;
import com.andrei1058.hologramapi.HologramPage;
import com.andrei1058.hologramapi.content.HologramClickListener;
import com.andrei1058.hologramapi.content.LineTextContent;
import com.andrei1058.stevesus.api.SteveSusAPI;
import com.andrei1058.stevesus.api.arena.Arena;
import com.andrei1058.stevesus.api.arena.team.Team;
import com.andrei1058.stevesus.api.hook.hologram.HologramI;
import com.andrei1058.stevesus.api.hook.hologram.HologramManager;
import com.andrei1058.stevesus.api.locale.Message;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

public class SecurityMonitor {

private static HologramClickListener clickListener;
// private static HologramClickListener clickListener;

private final Location location;
private Hologram hologram;
private @Nullable HologramI hologram;

public SecurityMonitor(Location location){
this.location = location;
this.hologram = new Hologram(location, 2);
HologramPage page = hologram.getPage(0);
assert page != null;
page.setLineContent(0, new LineTextContent(player -> SteveSusAPI.getInstance().getLocaleHandler().getMsg(player, Message.SECURITY_MONITOR_HOLOGRAM_LINE1)));
page.setLineContent(1, new LineTextContent(player -> SteveSusAPI.getInstance().getLocaleHandler().getMsg(player, Message.SECURITY_MONITOR_HOLOGRAM_LINE2)));

if (clickListener == null){
clickListener = (player, lineClickType) -> {
Arena arena = SteveSusAPI.getInstance().getArenaHandler().getArenaByPlayer(player);
if (arena == null) return;
if (arena.getCamHandler() == null) return;
if (arena.getCamHandler().getCams().isEmpty()) return;
if (arena.isSpectator(player)) return;
Team playerTeam = arena.getPlayerTeam(player);
if (playerTeam == null) return;
if (playerTeam.getIdentifier().endsWith("-ghost")) return;
arena.getCamHandler().startWatching(player, arena, arena.getCamHandler().getCams().get(0));
};

var holoManager = HologramManager.getInstance().getProvider();

if (null != holoManager) {
this.hologram = holoManager.spawnHologram(location);

var langManager = SteveSusAPI.getInstance().getLocaleHandler();
this.hologram.setPageContent(Arrays.asList(
player -> langManager.getMsg(player, Message.SECURITY_MONITOR_HOLOGRAM_LINE1),
player -> langManager.getMsg(player, Message.SECURITY_MONITOR_HOLOGRAM_LINE2)
));
}

hologram.allowCollisions(true);
hologram.setClickListener(clickListener);
// fixme
// if (clickListener == null){
// clickListener = (player, lineClickType) -> {
// Arena arena = SteveSusAPI.getInstance().getArenaHandler().getArenaByPlayer(player);
// if (arena == null) return;
// if (arena.getCamHandler() == null) return;
// if (arena.getCamHandler().getCams().isEmpty()) return;
// if (arena.isSpectator(player)) return;
// Team playerTeam = arena.getPlayerTeam(player);
// if (playerTeam == null) return;
// if (playerTeam.getIdentifier().endsWith("-ghost")) return;
// arena.getCamHandler().startWatching(player, arena, arena.getCamHandler().getCams().get(0));
// };
// }

// fixme
// hologram.allowCollisions(true);
// hologram.setClickListener(clickListener);
}

public Hologram getHologram() {
public @Nullable HologramI getHologram() {
return hologram;
}

public Location getLocation() {
return location;
}

public void setHologram(Hologram hologram) {
public void setHologram(@Nullable HologramI hologram) {
this.hologram = hologram;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.andrei1058.stevesus.api.arena.vent;

import com.andrei1058.hologramapi.Hologram;
import com.andrei1058.hologramapi.HologramPage;
import com.andrei1058.hologramapi.content.LineTextContent;
import com.andrei1058.stevesus.api.SteveSusAPI;
import com.andrei1058.stevesus.api.hook.hologram.HologramI;
import com.andrei1058.stevesus.api.hook.hologram.HologramManager;
import com.andrei1058.stevesus.api.locale.Message;
import com.andrei1058.stevesus.common.CommonManager;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.LinkedList;
Expand All @@ -21,26 +21,28 @@ public class Vent {
private final Location location;
private final LinkedList<Vent> connections = new LinkedList<>();
private ItemStack displayItem;
private final Hologram hologram;
private @Nullable HologramI hologram;

/**
* Create a vent.
*
* @param identifier unique id.
* @param block trap block on which players must shift to start venting.
*/
public Vent(@NotNull String identifier, @NotNull Location location, @NotNull ItemStack displayItem) {
this.identifier = identifier;
this.location = location;
this.location.setX(location.getBlockX() + 0.5);
this.location.setZ(location.getBlockZ() + 0.5);
this.displayItem = CommonManager.getINSTANCE().getItemSupport().addTag(displayItem, "nextVent", identifier);
hologram = new Hologram(location.clone().add(0, 0.5, 0), 1);
HologramPage page = hologram.getPage(0);
assert page != null;
page.setLineContent(0, new LineTextContent(s -> SteveSusAPI.getInstance().getLocaleHandler().getMsg(s, Message.VENT_HOLO)));
hologram.hide();
hologram.allowCollisions(false);

if (null == HologramManager.getInstance().getProvider()) {
var holoManager = HologramManager.getInstance().getProvider();
hologram = holoManager.spawnHologram(location.clone().add(0, 0.5, 0));
hologram.setPageContent(List.of(
receiver -> SteveSusAPI.getInstance().getLocaleHandler().getMsg(receiver, Message.VENT_HOLO)
));
hologram.hideToAll();
}
}

/**
Expand Down Expand Up @@ -108,7 +110,7 @@ public boolean equals(Object o) {
return vent.getIdentifier().equals(getIdentifier());
}

public Hologram getHologram() {
public @Nullable HologramI getHologram() {
return hologram;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.andrei1058.stevesus.api.hook.hologram;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.function.Function;

/**
* Hologram interface to make it work with any hologram dependency.
* Used as Wrapper.
*/
public interface HologramI {

/**
* @param pageContent per player lines.
*/
void setPageContent(List<Function<Player, String>> pageContent);

/**
* Make hologram invisible to everyone.
*/
void hideToAll();

/**
* Refresh hologram for given player.
*/

void refreshLines(Player player);

void refreshForAll();

/**
* Toggle {@link #hideToAll()}.
*/
void unHide();

void showToPlayer(Player player);
void hideFromPlayer(Player player);

/**
* Destroy hologram.
* Remove any trace of players and worlds etc.
*/
void remove();

boolean isHiddenFor(Player player);

Location getLocation();

/**
* Remove any trace of the given player to avoid memory leaks.
*/
void destroyPlayer(Player player);
}
Loading