Waitingrow done for testing!
This commit is contained in:
parent
2f7c90be62
commit
0c53cfae5e
6 changed files with 119 additions and 7 deletions
|
@ -4,10 +4,7 @@ import club.minnced.discord.webhook.WebhookClient;
|
|||
import club.minnced.discord.webhook.WebhookClientBuilder;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.AntiFreerunListener;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.DirectionalGateListener;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.FastpassListeners;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.StatusChangeListener;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.*;
|
||||
import nl.sbdeveloper.themeparkplus.managers.DBManager;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
||||
import nl.sbdeveloper.themeparkplus.util.LGUtil;
|
||||
|
@ -140,6 +137,7 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners...");
|
||||
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new FastpassListeners(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new WaitingTimeListener(), this);
|
||||
if (getSConfig().getFile().getBoolean("AntiFreerun.Enabled")) {
|
||||
Bukkit.getPluginManager().registerEvents(new AntiFreerunListener(), this);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package nl.sbdeveloper.themeparkplus.api;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||
|
@ -16,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlusAPI {
|
||||
private static HashMap<Location, Gate> gates = new HashMap<>();
|
||||
|
@ -97,7 +99,7 @@ public class PlusAPI {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a row by the location
|
||||
* Get a row by the rideid
|
||||
*
|
||||
* @param rideID The rideID
|
||||
* @return The row
|
||||
|
@ -106,6 +108,28 @@ public class PlusAPI {
|
|||
return rows.get(rideID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a row by the location
|
||||
*
|
||||
* @param loc The location
|
||||
* @return The row
|
||||
*/
|
||||
@NotNull
|
||||
public static Optional<WaitingRow> getRow(Location loc) {
|
||||
return rows.values().stream().filter(row -> row.getRegion().contains(BukkitAdapter.asBlockVector(loc))).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a row by the sign location
|
||||
*
|
||||
* @param signLoc The sign location
|
||||
* @return The row
|
||||
*/
|
||||
@NotNull
|
||||
public static Optional<WaitingRow> getRowBySign(Location signLoc) {
|
||||
return rows.values().stream().filter(row -> row.getSignLocations().contains(signLoc)).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the rows
|
||||
*
|
||||
|
|
|
@ -14,7 +14,7 @@ public class WaitingRow {
|
|||
@Getter @Setter private String rideID;
|
||||
@Getter @Setter private Region region;
|
||||
@Getter @Setter private int waitingPlayers = 0;
|
||||
@Getter @Setter private int waitingTimeMinutes = 0;
|
||||
@Getter @Setter private double waitingTimeMinutes = 0;
|
||||
private ArrayList<Location> signLocations = new ArrayList<>();
|
||||
|
||||
public WaitingRow(String rideID, Region region) {
|
||||
|
|
|
@ -6,13 +6,17 @@ import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
|||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Sign setup listener
|
||||
|
@ -72,4 +76,21 @@ public class SignListeners implements Listener {
|
|||
p.sendMessage(ConfigUtil.getMessage("General.IncorrectSign"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDestroySign(BlockBreakEvent e) {
|
||||
BlockState signblocks = e.getBlock().getState();
|
||||
if ((signblocks instanceof Sign)) {
|
||||
Optional<WaitingRow> rowOptional = PlusAPI.getRowBySign(e.getBlock().getLocation());
|
||||
if (!rowOptional.isPresent()) return;
|
||||
|
||||
WaitingRow row = rowOptional.get();
|
||||
if (row.getSignLocations().size() == 1) {
|
||||
PlusAPI.removeRow(row);
|
||||
} else {
|
||||
row.getSignLocations().remove(e.getBlock().getLocation());
|
||||
}
|
||||
ThemeParkPlus.getData().save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package nl.sbdeveloper.themeparkplus.listeners;
|
||||
|
||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WaitingTimeListener implements Listener {
|
||||
|
||||
private static final double PER_PLAYER = ThemeParkPlus.getSConfig().getFile().getDouble("WaitingRow.MinutesPerPlayer");
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent e) {
|
||||
if (e.getTo() == null) return;
|
||||
if ((e.getFrom().getBlockX() != e.getTo().getBlockX())
|
||||
|| (e.getFrom().getBlockY() != e.getTo().getBlockY())
|
||||
|| (e.getFrom().getBlockZ() != e.getTo().getBlockZ())) {
|
||||
Optional<WaitingRow> rowOptional = PlusAPI.getRow(e.getFrom());
|
||||
Optional<WaitingRow> rowOptional2 = PlusAPI.getRow(e.getTo());
|
||||
|
||||
WaitingRow row = null;
|
||||
int waitingNew = 0;
|
||||
double waitingTimeNew = 0;
|
||||
if (!rowOptional.isPresent() && rowOptional2.isPresent()) {
|
||||
//ENTER
|
||||
row = rowOptional2.get();
|
||||
waitingNew = row.getWaitingPlayers() + 1;
|
||||
waitingTimeNew = row.getWaitingTimeMinutes() + PER_PLAYER;
|
||||
} else if (rowOptional.isPresent() && !rowOptional2.isPresent()) {
|
||||
//LEAVE
|
||||
row = rowOptional.get();
|
||||
waitingNew = row.getWaitingPlayers() - 1;
|
||||
waitingTimeNew = row.getWaitingTimeMinutes() - PER_PLAYER;
|
||||
}
|
||||
|
||||
if (row == null) return;
|
||||
|
||||
row.setWaitingPlayers(waitingNew);
|
||||
row.setWaitingTimeMinutes(waitingTimeNew);
|
||||
|
||||
for (Location location : row.getSignLocations()) {
|
||||
Block signblock = location.getBlock();
|
||||
BlockState signblocks = signblock.getState();
|
||||
if ((signblocks instanceof Sign)) {
|
||||
Sign signs = (Sign) signblocks;
|
||||
signs.setLine(3, waitingNew + " min.");
|
||||
signs.update();
|
||||
} else {
|
||||
Bukkit.getLogger().warning(ConfigUtil.getMessage("WaitingRow.WrongLocation", Collections.singletonMap("%ridename%", row.getRideID())));
|
||||
PlusAPI.removeRow(row);
|
||||
ThemeParkPlus.getData().save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,3 +35,4 @@ Lamps:
|
|||
TurnedOff: '&aLamps in region turned off!'
|
||||
WaitingRow:
|
||||
SignCreated: '&aYou''ve successfully created a waitingrow sign!'
|
||||
WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.'
|
Reference in a new issue