3
0
Fork 0

Started with waiting rows

This commit is contained in:
stijnb1234 2020-06-03 16:27:33 +02:00
parent 328b8d670f
commit 2f7c90be62
7 changed files with 99 additions and 34 deletions

View file

@ -13,6 +13,7 @@ import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
import nl.sbdeveloper.themeparkplus.util.LGUtil;
import nl.sbdeveloper.themeparkplus.util.License;
import nl.sbdeveloper.themeparkplus.sbutils.YamlFile;
import nl.sbdeveloper.themeparkplus.util.WEUtil;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.RegisteredServiceProvider;
@ -37,6 +38,8 @@ public final class ThemeParkPlus extends JavaPlugin {
private static Economy econ = null;
private static WebhookClient webhookClient;
private static WEUtil weUtil;
private int configVersion = 2;
@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 {
new LGUtil();
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
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...");
try {
data.load();
@ -214,6 +220,10 @@ public final class ThemeParkPlus extends JavaPlugin {
return econ;
}
public static WEUtil getWEUtil() {
return weUtil;
}
public static WebhookClient getWebhookClient() {
return webhookClient;
}

View file

@ -4,6 +4,7 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
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.XMaterial;
import org.bukkit.Location;
@ -18,6 +19,7 @@ import java.util.List;
public class PlusAPI {
private static HashMap<Location, Gate> gates = new HashMap<>();
private static HashMap<String, WaitingRow> rows = new HashMap<>();
/**
* Add a gate
@ -66,6 +68,53 @@ public class PlusAPI {
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
*

View file

@ -1,7 +1,5 @@
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 lombok.AllArgsConstructor;
import lombok.Getter;

View file

@ -230,6 +230,7 @@ public class TPPCMD implements CommandExecutor {
if (gate != null) {
PlusAPI.addGate(gate);
ThemeParkPlus.getData().save();
}
Block b = loc.getBlock();
@ -268,6 +269,7 @@ public class TPPCMD implements CommandExecutor {
Gate gate = PlusAPI.getGate(loc);
if (gate != null) {
PlusAPI.removeGate(gate);
ThemeParkPlus.getData().save();
}
if (!LGUtil.isOpen(b)) {

View file

@ -1,5 +1,6 @@
package nl.sbdeveloper.themeparkplus.listeners;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import nl.sbdeveloper.themeparkplus.api.PlusAPI;
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
@ -38,9 +39,11 @@ public class DirectionalGateListener implements Listener {
LGUtil.closeGate(oldBlock);
} else {
PlusAPI.removeGate(gate);
ThemeParkPlus.getData().save();
return;
}
PlusAPI.removeGate(gate);
ThemeParkPlus.getData().save();
} else {
gate.setPassedCount(gate.getPassedCount() + 1);
}
@ -60,9 +63,11 @@ public class DirectionalGateListener implements Listener {
LGUtil.closeGate(oldBlock);
} else {
PlusAPI.removeGate(gate);
ThemeParkPlus.getData().save();
return;
}
PlusAPI.removeGate(gate);
ThemeParkPlus.getData().save();
} else {
gate.setPassedCount(gate.getPassedCount() + 1);
}

View file

@ -1,7 +1,9 @@
package nl.sbdeveloper.themeparkplus.listeners;
import com.sk89q.worldedit.regions.Region;
import me.paradoxpixel.themepark.api.API;
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.entity.Player;
@ -58,8 +60,12 @@ public class SignListeners implements Listener {
e.setLine(0, wrLineOne);
e.setLine(1, wrLineTwo);
Region selected = ThemeParkPlus.getWEUtil().getSelection(p);
//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"));
} else {

View file

@ -2,49 +2,44 @@ package nl.sbdeveloper.themeparkplus.util;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
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.world.World;
import com.sk89q.worldedit.regions.RegionSelector;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public class WEUtil {
private static boolean newVersion;
private static WorldEditPlugin wep;
public WEUtil() {
newVersion = XMaterial.isNewVersion();
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
}
@Nullable
public static Region getSelection(Player p) {
if (newVersion) {
LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
Region s;
public Region getSelection(Player p) {
LocalSession session;
try {
s = l.getSelection(l.getSelectionWorld());
} catch (IncompleteRegionException e) {
session = wep.getSession(p);
} catch (Exception e) {
// sometimes after a reload getSession create errors with WorldEdit, this prevent error spam
return null;
}
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);
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) {
Bukkit.getLogger().warning("[ThemeParkPlus] Region still incomplete");
}
} 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;