3
0
Fork 0

Fixed messages file, added data saving and some more fixes.

This commit is contained in:
stijnb1234 2020-04-18 09:53:19 +02:00
parent b487444b65
commit 0c16981ef6
10 changed files with 172 additions and 127 deletions

View file

@ -26,6 +26,7 @@ import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
@ -156,13 +157,25 @@ public final class ThemeParkPlus extends JavaPlugin {
Logger.logError("Couldn't find classes for Lamp & Gate util. The plugin won't work as intended.", true); Logger.logError("Couldn't find classes for Lamp & Gate util. The plugin won't work as intended.", true);
} }
Logger.logInfo("Loading data...", true);
try {
data.load();
} catch (SQLException e) {
e.printStackTrace();
Logger.logError("Couldn't load data! Something went wrong.", true);
}
Logger.logInfo("Plugin enabled!", true); Logger.logInfo("Plugin enabled!", true);
Logger.logInfo("-------------------------------", true); Logger.logInfo("-------------------------------", true);
} }
@Override @Override
public void onDisable() { public void onDisable() {
Logger.logInfo("Saving data to data file...", true);
data.save();
if (getSConfig().getFile().getBoolean("DiscordWebhook.Enabled")) { if (getSConfig().getFile().getBoolean("DiscordWebhook.Enabled")) {
Logger.logInfo("Breaking discord connection...", true);
webhookClient.close(); webhookClient.close();
} }
Logger.logInfo("Plugin disabled!", true); Logger.logInfo("Plugin disabled!", true);

View file

@ -18,15 +18,6 @@ public class Gate {
private boolean isDirectional = false; private boolean isDirectional = false;
private WalkingDirection direction; private WalkingDirection direction;
/**
* Constructor for a normal gate.
*
* @param loc The gate location
*/
public Gate(Location loc) {
this.loc = loc;
}
/** /**
* Constructor for a directional gate. * Constructor for a directional gate.
* *

View file

@ -4,6 +4,7 @@ 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;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.Cuboid; import nl.sbdeveloper.themeparkplus.util.Cuboid;
import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.LGUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -14,8 +15,11 @@ import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class TPPCMD implements CommandExecutor { public class TPPCMD implements CommandExecutor {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
@ -25,13 +29,13 @@ public class TPPCMD implements CommandExecutor {
return infoCommand(sender); return infoCommand(sender);
} else if (args[0].equalsIgnoreCase("opengate") && args.length == 5) { } else if (args[0].equalsIgnoreCase("opengate") && args.length == 5) {
if (!sender.hasPermission("tpp.opengate")) { if (!sender.hasPermission("tpp.opengate")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return openGate(sender, args, 0, null); return openGate(sender, args, 0, null);
} else if (args[0].equalsIgnoreCase("opengate") && args.length == 6) { } else if (args[0].equalsIgnoreCase("opengate") && args.length == 6) {
if (!sender.hasPermission("tpp.opengate")) { if (!sender.hasPermission("tpp.opengate")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
@ -44,13 +48,13 @@ public class TPPCMD implements CommandExecutor {
return openGate(sender, args, 0, dir); return openGate(sender, args, 0, dir);
} catch (Exception ex2) { } catch (Exception ex2) {
sender.sendMessage(ChatColor.RED + "Unknown direction or amount."); sender.sendMessage(ConfigUtil.getMessage("Gates.UnknownDirAndAmount"));
return true; return true;
} }
} }
} else if (args[0].equalsIgnoreCase("opengate") && args.length == 7) { } else if (args[0].equalsIgnoreCase("opengate") && args.length == 7) {
if (!sender.hasPermission("tpp.opengate")) { if (!sender.hasPermission("tpp.opengate")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
@ -60,7 +64,7 @@ public class TPPCMD implements CommandExecutor {
try { try {
amount = Integer.parseInt(args[5]); amount = Integer.parseInt(args[5]);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "Unknown amount."); sender.sendMessage(ConfigUtil.getMessage("General.IncorrectAmount"));
ex.printStackTrace(); ex.printStackTrace();
return true; return true;
} }
@ -68,27 +72,27 @@ public class TPPCMD implements CommandExecutor {
try { try {
dir = WalkingDirection.valueOf(args[6]); dir = WalkingDirection.valueOf(args[6]);
} catch (Exception ex2) { } catch (Exception ex2) {
sender.sendMessage(ChatColor.RED + "Unknown direction."); sender.sendMessage(ConfigUtil.getMessage("Gates.UnknownDir"));
return true; return true;
} }
return openGate(sender, args, amount, dir); return openGate(sender, args, amount, dir);
} else if (args[0].equalsIgnoreCase("closegate") && args.length == 5) { } else if (args[0].equalsIgnoreCase("closegate") && args.length == 5) {
if (!sender.hasPermission("tpp.closegate")) { if (!sender.hasPermission("tpp.closegate")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return closeGate(sender, args); return closeGate(sender, args);
} else if (args[0].equalsIgnoreCase("lampon") && args.length == 5) { } else if (args[0].equalsIgnoreCase("lampon") && args.length == 5) {
if (!sender.hasPermission("tpp.lampon")) { if (!sender.hasPermission("tpp.lampon")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return lampTurnOnCommand(sender, args, 0); return lampTurnOnCommand(sender, args, 0);
} else if (args[0].equalsIgnoreCase("lampon") && args.length == 6) { } else if (args[0].equalsIgnoreCase("lampon") && args.length == 6) {
if (!sender.hasPermission("tpp.lampon")) { if (!sender.hasPermission("tpp.lampon")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
@ -96,26 +100,26 @@ public class TPPCMD implements CommandExecutor {
try { try {
amount = Integer.parseInt(args[5]); amount = Integer.parseInt(args[5]);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "Unknown amount."); sender.sendMessage(ConfigUtil.getMessage("General.IncorrectAmount"));
return true; return true;
} }
return lampTurnOnCommand(sender, args, amount); return lampTurnOnCommand(sender, args, amount);
} else if (args[0].equalsIgnoreCase("lampoff") && args.length == 5) { } else if (args[0].equalsIgnoreCase("lampoff") && args.length == 5) {
if (!sender.hasPermission("tpp.lampoff")) { if (!sender.hasPermission("tpp.lampoff")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return lampTurnOffCommand(sender, args); return lampTurnOffCommand(sender, args);
} else if (args[0].equalsIgnoreCase("lampson") && args.length == 8) { } else if (args[0].equalsIgnoreCase("lampson") && args.length == 8) {
if (!sender.hasPermission("tpp.lampson")) { if (!sender.hasPermission("tpp.lampson")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return lampsTurnOnCommand(sender, args, 0); return lampsTurnOnCommand(sender, args, 0);
} else if (args[0].equalsIgnoreCase("lampson") && args.length == 9) { } else if (args[0].equalsIgnoreCase("lampson") && args.length == 9) {
if (!sender.hasPermission("tpp.lampson")) { if (!sender.hasPermission("tpp.lampson")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
@ -123,14 +127,14 @@ public class TPPCMD implements CommandExecutor {
try { try {
amount = Integer.parseInt(args[8]); amount = Integer.parseInt(args[8]);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sender.sendMessage(ChatColor.RED + "Unknown amount."); sender.sendMessage(ConfigUtil.getMessage("General.IncorrectAmount"));
return true; return true;
} }
return lampsTurnOnCommand(sender, args, amount); return lampsTurnOnCommand(sender, args, amount);
} else if (args[0].equalsIgnoreCase("lampsoff") && args.length == 8) { } else if (args[0].equalsIgnoreCase("lampsoff") && args.length == 8) {
if (!sender.hasPermission("tpp.lampsoff")) { if (!sender.hasPermission("tpp.lampsoff")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to do this."); sender.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return true; return true;
} }
return lampsTurnOffCommand(sender, args); return lampsTurnOffCommand(sender, args);
@ -188,7 +192,7 @@ public class TPPCMD implements CommandExecutor {
Block b = loc.getBlock(); Block b = loc.getBlock();
if (LGUtil.isOpenable(b)) { if (LGUtil.isOpenable(b)) {
if (LGUtil.isOpen(b)) { if (LGUtil.isOpen(b)) {
sender.sendMessage(ChatColor.RED + "That gate is already opened!"); sender.sendMessage(ConfigUtil.getMessage("Gates.AlreadyOpen"));
return true; return true;
} }
if (gate != null && gate.isDirectional()) { if (gate != null && gate.isDirectional()) {
@ -197,14 +201,14 @@ public class TPPCMD implements CommandExecutor {
LGUtil.openGate(b); LGUtil.openGate(b);
} }
} else { } else {
sender.sendMessage(ChatColor.RED + "That block is not a gate."); sender.sendMessage(ConfigUtil.getMessage("Gates.NoGate"));
return true; return true;
} }
if (amount != 0) { if (amount != 0) {
sender.sendMessage(ChatColor.GREEN + "Gate opened for " + amount + " players!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Gates.Opened"));
} else { } else {
sender.sendMessage(ChatColor.GREEN + "Gate opened!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Gates.OpenedAmount", Collections.singletonMap("%amount%", String.valueOf(amount))));
} }
return true; return true;
} }
@ -224,16 +228,16 @@ public class TPPCMD implements CommandExecutor {
} }
if (!LGUtil.isOpen(b)) { if (!LGUtil.isOpen(b)) {
sender.sendMessage(ChatColor.RED + "That gate is already closed!"); sender.sendMessage(ConfigUtil.getMessage("Gates.AlreadyClosed"));
return true; return true;
} }
LGUtil.closeGate(b); LGUtil.closeGate(b);
} else { } else {
sender.sendMessage(ChatColor.RED + "That block is not a gate."); sender.sendMessage(ConfigUtil.getMessage("Gates.NoGate"));
return true; return true;
} }
sender.sendMessage(ChatColor.GREEN + "Gate closed!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Gates.Closed"));
return true; return true;
} }
@ -247,19 +251,19 @@ public class TPPCMD implements CommandExecutor {
if (secOn == 0) { if (secOn == 0) {
if (!LGUtil.zetLampAan(block)) { if (!LGUtil.zetLampAan(block)) {
sender.sendMessage(ChatColor.RED + "Couldn't turn the lamp on. Maybe it's not a lamp, or it's already on."); sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn"));
return true; return true;
} }
sender.sendMessage(ChatColor.GREEN + "Lamp turned on!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOn"));
} else { } else {
if (!LGUtil.zetLampAan(block)) { if (!LGUtil.zetLampAan(block)) {
sender.sendMessage(ChatColor.RED + "Couldn't turn the lamp on. Maybe it's not a lamp, or it's already on."); sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn"));
return true; return true;
} }
Bukkit.getScheduler().runTaskLater(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block), secOn * 20); Bukkit.getScheduler().runTaskLater(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block), secOn * 20);
sender.sendMessage(ChatColor.GREEN + "Lamp turned on for " + secOn + " second(s)!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn))));
} }
return true; return true;
} }
@ -272,11 +276,11 @@ public class TPPCMD implements CommandExecutor {
Location loc = new Location(bworld, bx, by, bz); Location loc = new Location(bworld, bx, by, bz);
if (!LGUtil.zetLampUit(loc.getBlock())) { if (!LGUtil.zetLampUit(loc.getBlock())) {
sender.sendMessage(ChatColor.RED + "Couldn't turn the lamp off. Maybe it's not a lamp, or it's already off."); sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn"));
return true; return true;
} }
sender.sendMessage(ChatColor.GREEN + "Lamp turned off!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOff"));
return true; return true;
} }
@ -300,7 +304,7 @@ public class TPPCMD implements CommandExecutor {
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> {
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampAan(block)); if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampAan(block));
})); }));
sender.sendMessage(ChatColor.GREEN + "Lamps in region turned on!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOn"));
} else { } else {
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> { Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> {
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampAan(block)); if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampAan(block));
@ -309,7 +313,7 @@ public class TPPCMD implements CommandExecutor {
Bukkit.getScheduler().runTaskLaterAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> { Bukkit.getScheduler().runTaskLaterAsynchronously(ThemeParkPlus.getInstance(), () -> cub.getBlocks().forEach(block -> {
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block)); if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block));
}), secOn * 20); }), secOn * 20);
sender.sendMessage(ChatColor.GREEN + "Lamps in region turned on for " + secOn + " seconds!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn))));
} }
return true; return true;
} }
@ -334,7 +338,7 @@ public class TPPCMD implements CommandExecutor {
if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block)); if (block.getType().name().contains("REDSTONE_LAMP")) Bukkit.getScheduler().runTask(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block));
})); }));
sender.sendMessage(ChatColor.GREEN + "Lamps in region turned off!"); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOff"));
return true; return true;
} }
} }

View file

@ -3,6 +3,7 @@ package nl.sbdeveloper.themeparkplus.listeners;
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;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.DirectionUtil; import nl.sbdeveloper.themeparkplus.util.DirectionUtil;
import nl.sbdeveloper.themeparkplus.util.LGUtil; import nl.sbdeveloper.themeparkplus.util.LGUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -46,7 +47,7 @@ public class DirectionalGateListener implements Listener {
if (loopdir == null) return; if (loopdir == null) return;
if (loopdir.getBlockFace() != gate.getDirection().getBlockFace()) { if (loopdir.getBlockFace() != gate.getDirection().getBlockFace()) {
e.getPlayer().teleport(oldLoc); e.getPlayer().teleport(oldLoc);
e.getPlayer().sendMessage(ChatColor.RED + "You can't walk in that direction."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Gates.WrongDir"));
return; return;
} }

View file

@ -25,6 +25,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class FastpassListeners implements Listener { public class FastpassListeners implements Listener {
@EventHandler @EventHandler
@ -33,21 +35,28 @@ public class FastpassListeners implements Listener {
String[] lines = e.getLines(); String[] lines = e.getLines();
if (!p.hasPermission("tpp.fastpass.create")) { if (!p.hasPermission("tpp.fastpass.create")) {
p.sendMessage(ChatColor.RED + "You don't have the permission to do this."); p.sendMessage(ConfigUtil.getMessage("General.NoPermission"));
return; return;
} }
if (!API.isAttraction(e.getLine(2))) { if (!API.isAttraction(e.getLine(2))) {
p.sendMessage(ChatColor.RED + e.getLine(2) + " is not an existing ride."); p.sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("ridename", e.getLine(2))));
return; return;
} }
String mLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.MachineSign.Row1"));
String mLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.MachineSign.Row2"));
String sLineOne = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row1"));
String sLineTwo = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row2"));
if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) { if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Machine") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
e.setLine(0, ChatColor.GRAY + "[" + ChatColor.GOLD + "ThemeParkPlus" + ChatColor.GRAY + "]"); e.setLine(0, mLineOne);
e.setLine(1, ChatColor.BLUE + "Machine"); e.setLine(1, mLineTwo);
} else if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) { } else if (lines[0].equalsIgnoreCase("[ThemeParkPlus]") && lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
e.setLine(0, ChatColor.GRAY + "[" + ChatColor.GOLD + "ThemeParkPlus" + ChatColor.GRAY + "]"); e.setLine(0, sLineOne);
e.setLine(1, ChatColor.RED + "Scanner"); e.setLine(1, sLineTwo);
} else {
p.sendMessage(ConfigUtil.getMessage("Fastpass.IncorrectSign"));
} }
} }
@ -55,8 +64,16 @@ public class FastpassListeners implements Listener {
public void onSignClick(PlayerInteractEvent e) { public void onSignClick(PlayerInteractEvent e) {
if (e.getClickedBlock() == null || e.getAction() != Action.RIGHT_CLICK_BLOCK || !(e.getClickedBlock().getState() instanceof Sign) || e.getHand() != EquipmentSlot.HAND) return; if (e.getClickedBlock() == null || e.getAction() != Action.RIGHT_CLICK_BLOCK || !(e.getClickedBlock().getState() instanceof Sign) || e.getHand() != EquipmentSlot.HAND) return;
String mLineOne = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.MachineSign.Row1")));
String mLineTwo = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.MachineSign.Row2")));
String sLineOne = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row1")));
String sLineTwo = ChatColor.stripColor(ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.ScannerSign.Row2")));
String ticketName = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.Item.DisplayName"));
Sign sign = (Sign) e.getClickedBlock().getState(); Sign sign = (Sign) e.getClickedBlock().getState();
if (ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase("Machine")) { if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(mLineOne) && !ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(sLineOne)) return;
if (ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase(mLineTwo)) {
//Buy a ticket //Buy a ticket
String attID = sign.getLine(2); String attID = sign.getLine(2);
if (!API.isAttraction(attID)) return; if (!API.isAttraction(attID)) return;
@ -74,8 +91,9 @@ public class FastpassListeners implements Listener {
if (ticket == null) return; if (ticket == null) return;
ItemMeta meta = ticket.getItemMeta(); ItemMeta meta = ticket.getItemMeta();
if (meta == null) return; if (meta == null) return;
meta.setDisplayName(ChatColor.GOLD + "Fasspass Ticket"); meta.setDisplayName(ticketName);
meta.setLore(Collections.singletonList(ChatColor.GOLD + "For: " + ConfigUtil.makecolored(att.getName()))); List<String> ticketLores = ConfigUtil.getLore("Fastpass.Item.Lore", Collections.singletonMap("%ridename", att.getName()));
meta.setLore(ticketLores);
ticket.setItemMeta(meta); ticket.setItemMeta(meta);
NBTItem item = new NBTItem(ticket); NBTItem item = new NBTItem(ticket);
@ -84,7 +102,7 @@ public class FastpassListeners implements Listener {
ticket = item.getItem(); ticket = item.getItem();
if (ThemeParkPlus.getEconomy().getBalance(e.getPlayer()) < price) { if (ThemeParkPlus.getEconomy().getBalance(e.getPlayer()) < price) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't pay this fastpass ticket."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.NotEnoughMoney"));
return; return;
} }
@ -92,7 +110,7 @@ public class FastpassListeners implements Listener {
if (content == null || content.getType() == null || content.getType() == Material.AIR) continue; if (content == null || content.getType() == null || content.getType() == Material.AIR) continue;
NBTItem nbtContent = new NBTItem(content); NBTItem nbtContent = new NBTItem(content);
if (content.getType() == XMaterial.PAPER.parseMaterial() && content.hasItemMeta() && nbtContent.hasKey("RideID") && nbtContent.getString("RideID").equalsIgnoreCase(attID)) { if (content.getType() == XMaterial.PAPER.parseMaterial() && content.hasItemMeta() && nbtContent.hasKey("RideID") && nbtContent.getString("RideID").equalsIgnoreCase(attID)) {
e.getPlayer().sendMessage(ChatColor.RED + "You already have a ticket for this ride."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.AlreadyHaveTicket"));
return; return;
} }
} }
@ -101,11 +119,14 @@ public class FastpassListeners implements Listener {
e.getPlayer().getInventory().addItem(ticket); e.getPlayer().getInventory().addItem(ticket);
e.getPlayer().updateInventory(); e.getPlayer().updateInventory();
e.getPlayer().sendMessage(ChatColor.GREEN + "Bought a Fastpass ticket for " + ConfigUtil.makecolored(att.getName()) + ChatColor.GREEN + ". You paid €" + String.format("%.2f", price) + " for it!"); HashMap<String, String> vars = new HashMap<>();
} else if (ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase("Scanner")) { vars.put("%ridename%", att.getName());
vars.put("%price%", String.format("%.2f", price));
e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.Bought", vars));
} else if (ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase(sLineTwo)) {
//Scan a ticket //Scan a ticket
if (!API.isAttraction(sign.getLine(2))) { if (!API.isAttraction(sign.getLine(2))) {
e.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect! The attraction doesn't exists."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.UnknownRide", Collections.singletonMap("%ridename%", sign.getLine(2))));
return; return;
} }
Attraction att = API.getAttraction(sign.getLine(2)); Attraction att = API.getAttraction(sign.getLine(2));
@ -114,12 +135,12 @@ public class FastpassListeners implements Listener {
NBTItem nbtContent = new NBTItem(content); NBTItem nbtContent = new NBTItem(content);
if (content.getType() == Material.AIR if (content.getType() == Material.AIR
|| !content.hasItemMeta() || !nbtContent.hasKey("RideID")) { || !content.hasItemMeta() || !nbtContent.hasKey("RideID")) {
e.getPlayer().sendMessage(ChatColor.RED + "You need a fastpass ticket to go through the fastpass line."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.NoTicket"));
return; return;
} }
if (att.getStatus() != Status.OPEN && att.getStatus() != Status.ACTIVE) { if (att.getStatus() != Status.OPEN && att.getStatus() != Status.ACTIVE) {
e.getPlayer().sendMessage(ChatColor.RED + "This attraction is closed."); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.RideClosed"));
return; return;
} }
@ -140,9 +161,9 @@ public class FastpassListeners implements Listener {
} }
e.getPlayer().getInventory().remove(e.getPlayer().getInventory().getItemInMainHand()); e.getPlayer().getInventory().remove(e.getPlayer().getInventory().getItemInMainHand());
e.getPlayer().updateInventory(); e.getPlayer().updateInventory();
e.getPlayer().sendMessage(ChatColor.GREEN + "Successfully redeemed your fastpass ticket!"); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.Redeemed"));
} catch (NumberFormatException | ArrayIndexOutOfBoundsException ex) { } catch (NumberFormatException | ArrayIndexOutOfBoundsException ex) {
e.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect!"); e.getPlayer().sendMessage(ConfigUtil.getMessage("Fastpass.IncorrectSign"));
} }
} }
} }

View file

@ -7,7 +7,6 @@ import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
import me.paradoxpixel.themepark.attraction.status.StatusManager; import me.paradoxpixel.themepark.attraction.status.StatusManager;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View file

@ -1,11 +1,54 @@
package nl.sbdeveloper.themeparkplus.util; package nl.sbdeveloper.themeparkplus.util;
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ConfigUtil { public class ConfigUtil {
@NotNull @NotNull
public static String makecolored(String str) { public static String makecolored(String str) {
return ChatColor.translateAlternateColorCodes('&', str); return ChatColor.translateAlternateColorCodes('&', str);
} }
@NotNull
public static List<String> getLore(String path, Map<String, String> vars) {
ArrayList<String> response = new ArrayList<>();
for (String str : ThemeParkPlus.getSConfig().getFile().getStringList(path)) {
for (Map.Entry<String, String> entry : vars.entrySet()) {
str = str.replaceAll(entry.getKey(), entry.getValue());
}
response.add(makecolored(str));
}
return response;
}
@NotNull
public static String getMessage(String path) {
return getMessage(path, new HashMap<>());
}
@NotNull
public static String getMessage(String path, Map<String, String> vars) {
String message = ThemeParkPlus.getMessages().getFile().getString(path);
if (message == null) return "";
for (Map.Entry<String, String> entry : vars.entrySet()) {
message = message.replaceAll(entry.getKey(), entry.getValue());
}
return makecolored(message);
}
public static boolean sendConsole(CommandSender sender) {
if (sender instanceof ConsoleCommandSender) {
return ThemeParkPlus.getSConfig().getFile().getBoolean("MessageInConsole");
} else {
return true;
}
}
} }

View file

@ -25,15 +25,4 @@ public class DirectionUtil {
} }
return null; return null;
} }
public static boolean isGoodDirection(WalkingDirection current, WalkingDirection good) {
if (current == WalkingDirection.EAST && good == WalkingDirection.EAST) {
return true;
} else if (current == WalkingDirection.NORTH && good == WalkingDirection.NORTH) {
return true;
} else if (current == WalkingDirection.SOUTH && good == WalkingDirection.SOUTH) {
return true;
} else return current == WalkingDirection.WEST && good == WalkingDirection.WEST;
}
} }

View file

@ -1,14 +1,18 @@
License: 'TP-ABC-ABC' License: 'TPABCD-1234-ABCD-1234SBD'
AntiFreerun: AntiFreerun:
Enabled: false Enabled: false
MessageInConsole: true
Fastpass: Fastpass:
ItemName: '&6ThemeParkTicket' Item:
DisplayName: '&6Fastpass Ticket'
Lore:
- '&6For: %ridename%'
MachineSign: MachineSign:
Row1: "&3[ThemePark]" Row1: "&8[&6ThemeParkPlus&8]"
Row2: "&bMachine" Row2: "&bMachine"
ControlSign: ScannerSign:
Row1: "&3[ThemePark]" Row1: "&8[&6ThemeParkPlus&8]"
Row2: "&bControl" Row2: "&bScanner"
DiscordWebhook: DiscordWebhook:
Enabled: false Enabled: false
WebhookURL: "" WebhookURL: ""
@ -24,10 +28,3 @@ DiscordWebhook:
MALFUNCTION: 0xAA00AA MALFUNCTION: 0xAA00AA
ACTIVE: 0x55FF55 ACTIVE: 0x55FF55
INACTIVE: 0xAA0000 INACTIVE: 0xAA0000
WaitingRows:
MinutesPerWaitingPerson: 2
Sign:
Row1: "&3[ThemePark]"
Row2: "&bWaitingrow"
Row3: "%AttractionName%"
Row4: "%WaitTime% min."

View file

@ -1,45 +1,32 @@
General: General:
OnlyForPlayers: "&cOnly players can run this command!" NoPermission: '&cYou don''t have the permission to do this.'
NoPermission: "&cYou don't have the permission to do this!" IncorrectAmount: '&cThis amount is incorrect.'
Gates: Gates:
Open: WrongDir: '&cYou can''t walk through this gate in that direction.'
ChooseDirection: "&cYou have to choose between: NORTH, EAST, SOUTH and WEST" UnknownDir: '&cThis direction is unknown. Choose between: NORTH, SOUTH, EAST, WEST'
AlreadyOpen: "&cThat gate is already opened!" UnknownDirAndAmount: '&cThis direction and amount are incorrect.'
Opened: "&aThat gate is now open!" AlreadyOpen: '&cThis gate is already opened.'
OpenedPlayers: "&aThat gate is now open! A maximum of %COUNT% %SINGMULTI:visitor:visitors% can now walk through it!" AlreadyClosed: '&cThis gate is already closed.'
Close: NoGate: '&cThis block is not a gate.'
AlreadyClosed: "&cThat gate is already closed!" Opened: '&aThe gate is opened!'
Closed: "&aThat gate is now closed!" OpenedAmount: '&aThe gate is opened for &f%amount% &aplayer(s)!'
NoGate: "&cThat block is not a gate!" Closed: '&aThe gate is closed!'
NoGateConsole: "&cThe gate on the location %LocationXYZ% in the world %World% couldn't be find! It's now removed of the data!"
InvalidDirection: "&cYou can't walk through that gate in this direction!"
Lamps:
TurnOn:
NoLampOrAlreadyOn: "&cCouldn't turn that lamp on! Maybe it's already on, or it's not a redstone lamp."
IncorrectNumber: "&cThe number of seconds isn't correct! Give a number please."
TurnedOn: "&aThat lamp is succesfully turned on!"
TurnedOnSeconds: "&fThat lamp is succesfully turned on for %COUNT% %SINGMULTI:second:seconds%!"
TurnOff:
NoLampOrAlreadyOff: "&cCouldn't turn that lamp off! Maybe it's already off, or it's not a redstone lamp."
TurnedOff: "&aThat lamp is succesfully turned off!"
Fastpass: Fastpass:
NotEnoughMoney: "&cYou don't have enough money for this Fastpass ticket!" IncorrectSign: '&cThis sign is incorrect. Please read the wiki for more information.'
AlreadyHasOne: "&cYou've already got a Fastpass ticket for this ride!" UnknownRide: '&cThe ride %ridename% &cdoes''nt exists.'
MoneyWithdrawed: "&aA amount of $%MoneyAmount%,- is taken of your account!" NotEnoughMoney: '&cYou can''t pay this ticket.'
WrongLocation: "&cThat sign contains wrong coordinates!" AlreadyHaveTicket: '&cYou''ve already got a ticket for this ride.'
Expired: "&cYour fastpass ticket is already expired!" Bought: '&aYou''ve successfully bought a ticket for the ride %ridename%&a. You''ve paid &f%price% &afor it.'
NotOpen: "&cThat ride is not open!" NoTicket: '&cYou need a fastpass ticket to go through the fastpass line.'
YouNeedATicket: "&cYou need a (correct) ticket to use the FastPass row!" RideClosed: '&cThis ride is closed.'
Succes: "&aHave fun in this ride!" Redeemed: '&aSuccessfully redeemed your fastpass ticket!'
Malfunction: Lamp:
ReasonQuestion: "&aPlease type the reason of the malfunction! (Type STOP to set it to Unknown)" ErrorOn: '&cCouldn''t turn the lamp on. Maybe it''s not a lamp, or it''s already on.'
Reported: "&aThe malfunction has been reported to the Technical Service!" ErrorOff: '&cCouldn''t turn the lamp off. Maybe it''s not a lamp, or it''s already off.'
Fixed: "&aThe malfunction has succesfully been removed!" TurnedOn: '&aLamp turned on!'
NotAllowedToChange: "&cYou can't change the status if a ride has a malfunction!" TurnedOnSec: '&aLamp turned on for &f%sec% &asecond(s)!'
WaitingRows: TurnedOff: '&aLamp turned off!'
WrongLocation: "&cA waitingrow sign (from the attraction %AttractionID%) couldn't be found! It will be deleted." Lamps:
WrongAttraction: "&cThat attraction doesn't exists!" TurnedOn: '&aLamps in region turned on!'
ForgotSelection: "&cYou forgot to select a region! Please select a point one (left) and point two (right) with a STICK." TurnedOnSec: '&aLamps in region turned on for &f%sec% &asecond(s)!'
PosOneSelected: "&aSuccesfully selected position one!" TurnedOff: '&aLamps in region turned off!'
PosTwoSelected: "&aSuccesfully selected position two!"
SignCreated: "&aYou've succesfully created a WaitingRow sign!"