Started with waiting rows
This commit is contained in:
parent
328b8d670f
commit
2f7c90be62
7 changed files with 99 additions and 34 deletions
|
@ -13,6 +13,7 @@ import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
||||||
import nl.sbdeveloper.themeparkplus.util.LGUtil;
|
import nl.sbdeveloper.themeparkplus.util.LGUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.License;
|
import nl.sbdeveloper.themeparkplus.util.License;
|
||||||
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
|
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
|
||||||
|
import nl.sbdeveloper.themeparkplus.util.WEUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
@ -37,6 +38,8 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
private static Economy econ = null;
|
private static Economy econ = null;
|
||||||
private static WebhookClient webhookClient;
|
private static WebhookClient webhookClient;
|
||||||
|
|
||||||
|
private static WEUtil weUtil;
|
||||||
|
|
||||||
private int configVersion = 2;
|
private int configVersion = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,14 +164,17 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading Lamp & Gate utils...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading Lamp & Gate util...");
|
||||||
try {
|
try {
|
||||||
new LGUtil();
|
new LGUtil();
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Bukkit.getLogger().severe("[ThemeParkPlus] Couldn't find classes for Lamp & Gate util. The plugin won't work as intended.");
|
Bukkit.getLogger().severe("[ThemeParkPlus] Lamp & Gate util not compatible with your Spigot version. The plugin won't work as intended.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading WorldEdit util...");
|
||||||
|
weUtil = new WEUtil();
|
||||||
|
|
||||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading data...");
|
Bukkit.getLogger().info("[ThemeParkPlus] Loading data...");
|
||||||
try {
|
try {
|
||||||
data.load();
|
data.load();
|
||||||
|
@ -214,6 +220,10 @@ public final class ThemeParkPlus extends JavaPlugin {
|
||||||
return econ;
|
return econ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WEUtil getWEUtil() {
|
||||||
|
return weUtil;
|
||||||
|
}
|
||||||
|
|
||||||
public static WebhookClient getWebhookClient() {
|
public static WebhookClient getWebhookClient() {
|
||||||
return webhookClient;
|
return webhookClient;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -18,6 +19,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class PlusAPI {
|
public class PlusAPI {
|
||||||
private static HashMap<Location, Gate> gates = new HashMap<>();
|
private static HashMap<Location, Gate> gates = new HashMap<>();
|
||||||
|
private static HashMap<String, WaitingRow> rows = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a gate
|
* Add a gate
|
||||||
|
@ -66,6 +68,53 @@ public class PlusAPI {
|
||||||
return gates;
|
return gates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a row
|
||||||
|
*
|
||||||
|
* @param row The row
|
||||||
|
*/
|
||||||
|
public static void addRow(WaitingRow row) {
|
||||||
|
rows.put(row.getRideID(), row);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a row
|
||||||
|
*
|
||||||
|
* @param row The row
|
||||||
|
*/
|
||||||
|
public static void removeRow(@NotNull WaitingRow row) {
|
||||||
|
rows.remove(row.getRideID());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a location is a row
|
||||||
|
*
|
||||||
|
* @param rideID The rideID
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
public static boolean isRow(String rideID) {
|
||||||
|
return rows.containsKey(rideID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a row by the location
|
||||||
|
*
|
||||||
|
* @param rideID The rideID
|
||||||
|
* @return The row
|
||||||
|
*/
|
||||||
|
public static WaitingRow getRow(String rideID) {
|
||||||
|
return rows.get(rideID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the rows
|
||||||
|
*
|
||||||
|
* @return Map with location and rows
|
||||||
|
*/
|
||||||
|
public static HashMap<String, WaitingRow> getRows() {
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ticket itemstack
|
* Get the ticket itemstack
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package nl.sbdeveloper.themeparkplus.api.objects;
|
package nl.sbdeveloper.themeparkplus.api.objects;
|
||||||
|
|
||||||
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
|
||||||
import com.sk89q.worldedit.regions.AbstractRegion;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -230,6 +230,7 @@ public class TPPCMD implements CommandExecutor {
|
||||||
|
|
||||||
if (gate != null) {
|
if (gate != null) {
|
||||||
PlusAPI.addGate(gate);
|
PlusAPI.addGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
Block b = loc.getBlock();
|
Block b = loc.getBlock();
|
||||||
|
@ -268,6 +269,7 @@ public class TPPCMD implements CommandExecutor {
|
||||||
Gate gate = PlusAPI.getGate(loc);
|
Gate gate = PlusAPI.getGate(loc);
|
||||||
if (gate != null) {
|
if (gate != null) {
|
||||||
PlusAPI.removeGate(gate);
|
PlusAPI.removeGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LGUtil.isOpen(b)) {
|
if (!LGUtil.isOpen(b)) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
||||||
|
@ -38,9 +39,11 @@ public class DirectionalGateListener implements Listener {
|
||||||
LGUtil.closeGate(oldBlock);
|
LGUtil.closeGate(oldBlock);
|
||||||
} else {
|
} else {
|
||||||
PlusAPI.removeGate(gate);
|
PlusAPI.removeGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlusAPI.removeGate(gate);
|
PlusAPI.removeGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
} else {
|
} else {
|
||||||
gate.setPassedCount(gate.getPassedCount() + 1);
|
gate.setPassedCount(gate.getPassedCount() + 1);
|
||||||
}
|
}
|
||||||
|
@ -60,9 +63,11 @@ public class DirectionalGateListener implements Listener {
|
||||||
LGUtil.closeGate(oldBlock);
|
LGUtil.closeGate(oldBlock);
|
||||||
} else {
|
} else {
|
||||||
PlusAPI.removeGate(gate);
|
PlusAPI.removeGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlusAPI.removeGate(gate);
|
PlusAPI.removeGate(gate);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
} else {
|
} else {
|
||||||
gate.setPassedCount(gate.getPassedCount() + 1);
|
gate.setPassedCount(gate.getPassedCount() + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package nl.sbdeveloper.themeparkplus.listeners;
|
package nl.sbdeveloper.themeparkplus.listeners;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import me.paradoxpixel.themepark.api.API;
|
import me.paradoxpixel.themepark.api.API;
|
||||||
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
||||||
|
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
|
||||||
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
||||||
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -58,8 +60,12 @@ public class SignListeners implements Listener {
|
||||||
e.setLine(0, wrLineOne);
|
e.setLine(0, wrLineOne);
|
||||||
e.setLine(1, wrLineTwo);
|
e.setLine(1, wrLineTwo);
|
||||||
|
|
||||||
|
Region selected = ThemeParkPlus.getWEUtil().getSelection(p);
|
||||||
|
|
||||||
//AND SETUP
|
//AND SETUP
|
||||||
WaitingRow row = new WaitingRow();
|
WaitingRow row = new WaitingRow(lines[2], selected);
|
||||||
|
PlusAPI.addRow(row);
|
||||||
|
ThemeParkPlus.getData().save();
|
||||||
|
|
||||||
p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated"));
|
p.sendMessage(ConfigUtil.getMessage("WaitingRow.SignCreated"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,49 +2,44 @@ package nl.sbdeveloper.themeparkplus.util;
|
||||||
|
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
|
||||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
|
||||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class WEUtil {
|
public class WEUtil {
|
||||||
private static boolean newVersion;
|
|
||||||
private static WorldEditPlugin wep;
|
private static WorldEditPlugin wep;
|
||||||
|
|
||||||
public WEUtil() {
|
public WEUtil() {
|
||||||
newVersion = XMaterial.isNewVersion();
|
|
||||||
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Region getSelection(Player p) {
|
public Region getSelection(Player p) {
|
||||||
if (newVersion) {
|
LocalSession session;
|
||||||
LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
|
|
||||||
Region s;
|
|
||||||
try {
|
try {
|
||||||
s = l.getSelection(l.getSelectionWorld());
|
session = wep.getSession(p);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// sometimes after a reload getSession create errors with WorldEdit, this prevent error spam
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getSelectedRegion(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Region getSelectedRegion(@Nullable LocalSession session) {
|
||||||
|
if (session != null && session.getSelectionWorld() != null) {
|
||||||
|
RegionSelector selector = session.getRegionSelector(session.getSelectionWorld());
|
||||||
|
|
||||||
|
if (selector.isDefined()) {
|
||||||
|
try {
|
||||||
|
return selector.getRegion();
|
||||||
} catch (IncompleteRegionException e) {
|
} catch (IncompleteRegionException e) {
|
||||||
return null;
|
Bukkit.getLogger().warning("[ThemeParkPlus] Region still incomplete");
|
||||||
}
|
}
|
||||||
if (s instanceof Polygonal2DSelection) {
|
|
||||||
Polygonal2DSelection polySel = (Polygonal2DSelection) s;
|
|
||||||
int minY = polySel.getNativeMinimumPoint().getBlockY();
|
|
||||||
int maxY = polySel.getNativeMaximumPoint().getBlockY();
|
|
||||||
return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Selection sel = wep.getSelection(p);
|
|
||||||
if (sel instanceof Polygonal2DSelection) {
|
|
||||||
Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
|
|
||||||
int minY = polySel.getNativeMinimumPoint().getBlockY();
|
|
||||||
int maxY = polySel.getNativeMaximumPoint().getBlockY();
|
|
||||||
return new Polygonal2DRegion((World) polySel.getWorld(), polySel.getNativePoints(), minY, maxY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Reference in a new issue