3
0
Fork 0

Initial commit

This commit is contained in:
BuildTools 2019-01-15 18:16:59 +01:00
commit 184d8c59cb
45 changed files with 2990 additions and 0 deletions

1
.idea/.name Normal file
View file

@ -0,0 +1 @@
Theme

13
.idea/compiler.xml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="themepark" />
</profile>
</annotationProcessing>
</component>
</project>

4
.idea/encodings.xml Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

14
.idea/misc.xml Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

24
pom.xml Normal file
View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>me.paradoxpixel</groupId>
<artifactId>themepark</artifactId>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,118 @@
package me.paradoxpixel.themepark;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.attraction.sign.SignManager;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.command.MenuCommand;
import me.paradoxpixel.themepark.command.ThemeParkCommand;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.database.DatabaseHandler;
import me.paradoxpixel.themepark.gui.GUIListener;
import me.paradoxpixel.themepark.listener.ClickListener;
import me.paradoxpixel.themepark.listener.ChangeListener;
import me.paradoxpixel.themepark.listener.PlayerListener;
import me.paradoxpixel.themepark.listener.SignListener;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
public class ThemeParkPlugin extends JavaPlugin {
private static ThemeParkPlugin instance;
private YamlConfig settings, attraction, message, signs, data;
private DatabaseHandler database;
@Override
public void onEnable() {
instance = this;
loadConfig();
loadListener();
loadCommand();
loadData();
loadDatabase();
}
private void loadConfig() {
settings = new YamlConfig("settings", this);
attraction = new YamlConfig("attraction", this);
message = new YamlConfig("message", this);
signs = new YamlConfig("signs", this);
data = new YamlConfig("data", this);
}
private void loadData() {
StatusManager.load();
AttractionMenu.load();
}
private void loadDatabase() {
database = new DatabaseHandler(settings);
}
private void loadCommand() {
getCommand("status").setExecutor(new MenuCommand());
String command = settings.getConfig().getString("command");
if(command == null || command.isEmpty())
return;
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
commandMap.register(command, new ThemeParkCommand(command));
} catch(ReflectiveOperationException e) {
e.printStackTrace();
}
}
private void loadListener() {
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new GUIListener(), this);
pm.registerEvents(new ClickListener(), this);
pm.registerEvents(new ChangeListener(), this);
pm.registerEvents(new SignListener(), this);
pm.registerEvents(new PlayerListener(), this);
}
@Override
public void onDisable() {
AttractionMenu.save();
SignManager.saveSigns();
database.disconnect();
instance = null;
}
public static ThemeParkPlugin getInstance() {
return instance;
}
public YamlConfig getSettings() {
return settings;
}
public YamlConfig getAttraction() {
return attraction;
}
public YamlConfig getMessage() {
return message;
}
public YamlConfig getSigns() {
return signs;
}
public YamlConfig getData() {
return data;
}
public DatabaseHandler getDatabaseHandler() {
return database;
}
}

View file

@ -0,0 +1,46 @@
package me.paradoxpixel.themepark.action;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.gui.GUIAction;
import me.paradoxpixel.themepark.utils.Message;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
public class TPUtils extends GUIAction {
private String id;
public TPUtils(String id) {
this.id = id;
}
@Override
public void click(Player player) {
player.closeInventory();
Attraction attraction = API.getAttraction(id);
if(attraction == null)
return;
if(!StatusManager.canTeleport(attraction.getStatus())) {
String message = Message.getMessage("attraction.teleport.status");
message = message.replace("{name}", attraction.getName());
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
player.sendMessage(Utils.color(message));
return;
}
player.teleport(attraction.getLocation());
if(player.isInsideVehicle())
if(player.getVehicle() instanceof Minecart)
return;
String message = Message.getMessage("attraction.teleport.success");
message = message.replace("{name}", attraction.getName());
player.sendMessage(Utils.color(message));
}
}

View file

@ -0,0 +1,148 @@
package me.paradoxpixel.themepark.api;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.Region;
import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent;
import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent;
import me.paradoxpixel.themepark.api.event.region.AddRegionEvent;
import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class API {
private static LinkedHashMap<String, Region> regions = new LinkedHashMap<>();
private static LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>();
public static void addRegion(Region region) {
if(isRegion(region.getId()))
return;
if(regions.size() >= 6)
return;
region = toLower(region);
regions.put(region.getId(), region);
AddRegionEvent event = new AddRegionEvent(region);
Bukkit.getPluginManager().callEvent(event);
}
public static boolean isRegion(String id) {
return regions.containsKey(id.toLowerCase());
}
public static boolean isRegionFull(String id) {
if(!isRegion(id))
return false;
return getRegion(id).getAttractions().size() >= 8;
}
public static Region getRegion(String id) {
return regions.get(id.toLowerCase());
}
public static HashMap<String, Region> getRegions() {
return new LinkedHashMap<>(regions);
}
public static void removeRegion(String id) {
if(!isRegion(id))
return;
HashMap<String, Attraction> map = new HashMap<>(attractions);
for(Map.Entry<String, Attraction> entry : map.entrySet()) {
Attraction attraction = entry.getValue();
if(!attraction.getRegion_id().equalsIgnoreCase(id))
continue;
removeAttraction(attraction.getId());
}
RemoveRegionEvent event = new RemoveRegionEvent(getRegion(id));
Bukkit.getPluginManager().callEvent(event);
regions.remove(id.toLowerCase());
}
public static void addAttraction(Attraction attraction) {
if(!isRegion(attraction.getRegion_id()))
return;
if(isRegionFull(attraction.getRegion_id()))
return;
if(isAttraction(attraction.getId()))
return;
attraction = toLower(attraction);
getRegion(attraction.getRegion_id()).addAttraction(attraction);
attractions.put(attraction.getId(), attraction);
AddAttractionEvent event = new AddAttractionEvent(attraction);
Bukkit.getPluginManager().callEvent(event);
}
public static boolean isAttraction(String id) {
return attractions.containsKey(id.toLowerCase());
}
public static Attraction getAttraction(String id) {
return attractions.get(id.toLowerCase());
}
public static Attraction getAttractionFromName(String name) {
for(Attraction attraction : attractions.values()) {
if(!color(attraction.getName()).equals(name))
continue;
return attraction;
}
return null;
}
public static HashMap<String, Attraction> getAttractions() {
return new LinkedHashMap<>(attractions);
}
public static void removeAttraction(String id) {
if(!isAttraction(id))
return;
Attraction attraction = getAttraction(id);
if(isRegion(attraction.getRegion_id()))
getRegion(attraction.getRegion_id()).removeAttraction(attraction);
attractions.remove(id.toLowerCase());
RemoveAttractionEvent event = new RemoveAttractionEvent(attraction);
Bukkit.getPluginManager().callEvent(event);
}
private static Region toLower(Region region) {
Region re = new Region(region.getId().toLowerCase(),
region.getName(),
region.getLore());
re.setAttractions(region.getAttractions());
return re;
}
private static Attraction toLower(Attraction attraction) {
return new Attraction(attraction.getId().toLowerCase(),
attraction.getName(),
attraction.getRegion_id().toLowerCase(),
attraction.getLocation(),
attraction.getType(),
attraction.getStatus());
}
private static String color(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
}

View file

@ -0,0 +1,72 @@
package me.paradoxpixel.themepark.api.attraction;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.api.attraction.component.Type;
import me.paradoxpixel.themepark.api.event.attraction.PreStatusChangeEvent;
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class Attraction {
private String id, name, region_id;
private Location location;
private Type type;
private Status status;
public Attraction(String id, String name, String region_id, Location location, Type type, Status status) {
this.id = id;
this.name = name;
this.region_id = region_id;
this.location = location;
this.type = type;
this.status = type.containsStatus(status) ? status : type.getDefefault();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getRegion_id() {
return region_id;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public Type getType() {
return type;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status, Player player) {
if(!type.hasStatus())
return;
if(!type.containsStatus(status))
return;
PreStatusChangeEvent event = new PreStatusChangeEvent(this, player, this.status, status);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled())
return;
this.status = status;
StatusChangeEvent e = new StatusChangeEvent(this, player, this.status, status);
Bukkit.getPluginManager().callEvent(e);
}
}

View file

@ -0,0 +1,96 @@
package me.paradoxpixel.themepark.api.attraction;
import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
public class Region {
private String id, name;
private List<String> lore;
private ArrayList<Attraction> attractions;
public Region(String id, String name, List<String> lore) {
this.id = id;
this.name = name;
this.lore = lore;
this.attractions = new ArrayList<>();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String string) {
if(string == null || string.equals(""))
return;
String old = name;
name = string;
ChangeRegionEvent event = new ChangeRegionEvent(this, old, string, lore, lore);
Bukkit.getPluginManager().callEvent(event);
}
public List<String> getLore() {
return lore;
}
public void setLore(List<String> lore) {
List<String> old = lore;
this.lore = lore;
ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore);
Bukkit.getPluginManager().callEvent(event);
}
public void setLore(int i, String string) {
if(lore.size() >= 4 || i >= 4)
return;
List<String> old = lore;
lore = new ArrayList<>();
lore.addAll(old);
if(!string.equals("NULL")) {
if (lore.size() >= i)
for (int a = 0; a <= (i - lore.size()); a++)
lore.add(" ");
lore.set(i, string);
} else {
lore.remove(i);
}
ChangeRegionEvent event = new ChangeRegionEvent(this, name, name, old, lore);
Bukkit.getPluginManager().callEvent(event);
}
public ArrayList<Attraction> getAttractions() {
return attractions;
}
public void setAttractions(ArrayList<Attraction> attractions) {
this.attractions = attractions;
}
public void addAttraction(Attraction attraction) {
if(!isAttraction(attraction))
attractions.add(attraction);
}
public boolean isAttraction(Attraction attraction) {
return attractions.contains(attraction);
}
public void removeAttraction(Attraction attraction) {
if(isAttraction(attraction))
attractions.remove(attraction);
}
}

View file

@ -0,0 +1,35 @@
package me.paradoxpixel.themepark.api.attraction.component;
public enum Status {
CONSTRUCTION, OPEN,
CLOSED, MAINTENANCE,
MALFUNCTION, ACTIVE,
INACTIVE, GLOBAL;
public static Status getStatus(String string) {
if(string == null)
return null;
string = string.toUpperCase();
switch(string) {
case "CONSTRUCTION":
return Status.CONSTRUCTION;
case "OPEN":
return Status.OPEN;
case "CLOSED":
return Status.CLOSED;
case "MAINTENANCE":
return Status.MAINTENANCE;
case "MALFUNCTION":
return Status.MALFUNCTION;
case "ACTIVE":
return Status.ACTIVE;
case "INACTIVE":
return Status.INACTIVE;
default:
return null;
}
}
}

View file

@ -0,0 +1,59 @@
package me.paradoxpixel.themepark.api.attraction.component;
public enum Type {
RIDE(true, Status.CLOSED, Status.CONSTRUCTION, Status.OPEN, Status.CLOSED, Status.MAINTENANCE, Status.MALFUNCTION),
SHOW(true, Status.CLOSED, Status.CONSTRUCTION, Status.ACTIVE, Status.INACTIVE),
GLOBAL(false, Status.GLOBAL);
private boolean status;
private Status def;
private Status[] array;
Type(boolean status, Status def, Status... array) {
this.status = status;
this.def = def;
this.array = array;
}
public boolean hasStatus() {
return status;
}
public Status getDefefault() {
return def;
}
public boolean containsStatus(Status status) {
if(status == null)
return false;
if(!hasStatus())
return false;
for(int i = 0; i < array.length; i++)
if(array[i] == status)
return true;
return false;
}
public static Type getType(String string) {
if(string == null)
return null;
string = string.toUpperCase();
switch(string) {
case "RIDE":
return Type.RIDE;
case "SHOW":
return Type.SHOW;
case "GLOBAL":
return Type.GLOBAL;
default:
return null;
}
}
}

View file

@ -0,0 +1,29 @@
package me.paradoxpixel.themepark.api.event.attraction;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class AddAttractionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Attraction attraction;
public AddAttractionEvent(Attraction attraction) {
this.attraction = attraction;
}
public Attraction getAttraction() {
return attraction;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,61 @@
package me.paradoxpixel.themepark.api.event.attraction;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class PreStatusChangeEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel;
private Attraction attraction;
private Player player;
private Status before, after;
public PreStatusChangeEvent(Attraction attraction, Player player, Status before, Status after) {
this.attraction = attraction;
this.player = player;
this.before = before;
this.after = after;
cancel = false;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean b) {
cancel = b;
}
public Attraction getAttraction() {
return attraction;
}
public Player getPlayer() {
return player;
}
public Status getStatusBefore() {
return before;
}
public Status getStatusAfter() {
return after;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,29 @@
package me.paradoxpixel.themepark.api.event.attraction;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class RemoveAttractionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Attraction attraction;
public RemoveAttractionEvent(Attraction attraction) {
this.attraction = attraction;
}
public Attraction getAttraction() {
return attraction;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,48 @@
package me.paradoxpixel.themepark.api.event.attraction;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class StatusChangeEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Attraction attraction;
private Player player;
private Status before, after;
public StatusChangeEvent(Attraction attraction, Player player, Status before, Status after) {
this.attraction = attraction;
this.player = player;
this.before = before;
this.after = after;
}
public Attraction getAttraction() {
return attraction;
}
public Player getPlayer() {
return player;
}
public Status getStatusBefore() {
return before;
}
public Status getStatusAfter() {
return after;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,30 @@
package me.paradoxpixel.themepark.api.event.region;
import me.paradoxpixel.themepark.api.attraction.Region;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class AddRegionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Region region;
public AddRegionEvent(Region region) {
this.region = region;
}
public Region getRegion() {
return region;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,53 @@
package me.paradoxpixel.themepark.api.event.region;
import me.paradoxpixel.themepark.api.attraction.Region;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import java.util.List;
public class ChangeRegionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Region region;
private String bname, aname;
private List<String> blore, alore;
public ChangeRegionEvent(Region region, String bname, String aname, List<String> blore, List<String> alore) {
this.region = region;
this.bname = bname;
this.aname = aname;
this.blore = blore;
this.alore = alore;
}
public Region getRegion() {
return region;
}
public String getNameBefore() {
return bname;
}
public String getNameAfter() {
return aname;
}
public List<String> getLoreBefore() {
return blore;
}
public List<String> getLoreAfter() {
return alore;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,30 @@
package me.paradoxpixel.themepark.api.event.region;
import me.paradoxpixel.themepark.api.attraction.Region;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class RemoveRegionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Region region;
public RemoveRegionEvent(Region region) {
this.region = region;
}
public Region getRegion() {
return region;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,170 @@
package me.paradoxpixel.themepark.attraction;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.action.TPUtils;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.Region;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.api.attraction.component.Type;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.gui.GUI;
import me.paradoxpixel.themepark.gui.GUIItem;
import me.paradoxpixel.themepark.utils.ItemBuilder;
import me.paradoxpixel.themepark.utils.LocationUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.List;
public class AttractionMenu {
private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
private static GUI gui;
private static HashMap<String, Integer> index = new HashMap<>();
public static void load() {
gui = new GUI(settings.getConfig().getString("menu.title"), 9);
loadData();
loadItems();
}
public static void reload() {
loadItems();
}
public static void save() {
for(Region region : API.getRegions().values()) {
config.getConfig().set("region." + region.getId() + ".name", region.getName());
config.getConfig().set("region." + region.getId() + ".lore", region.getLore());
}
for(Attraction attraction : API.getAttractions().values()) {
config.getConfig().set("attraction." + attraction.getId() + ".name", attraction.getName());
config.getConfig().set("attraction." + attraction.getId() + ".region_id", attraction.getRegion_id());
config.getConfig().set("attraction." + attraction.getId() + ".type", attraction.getType().toString());
config.getConfig().set("attraction." + attraction.getId() + ".status", attraction.getStatus().toString());
config.getConfig().set("attraction." + attraction.getId() + ".location", LocationUtils.toString(attraction.getLocation()));
}
config.save();
}
private static void loadData() {
if(!config.getConfig().contains("region"))
return;
if(!config.getConfig().isConfigurationSection("region"))
return;
ConfigurationSection section = config.getConfig().getConfigurationSection("region");
if(section.getKeys(false).isEmpty())
return;
for(String id : section.getKeys(false)) {
if(API.getRegions().size() >= 6) {
config.getConfig().set("regions." + id, null);
config.save();
continue;
}
String name = config.getConfig().getString("region." + id + ".name");
List<String> lore = config.getConfig().getStringList("region." + id + ".lore");
Region region = new Region(id, name, lore);
API.addRegion(region);
}
if(!config.getConfig().contains("attraction"))
return;
if(!config.getConfig().isConfigurationSection("attraction"))
return;
section = config.getConfig().getConfigurationSection("attraction");
if(section.getKeys(false).isEmpty())
return;
for(String id : section.getKeys(false)) {
String region_id = config.getConfig().getString("attraction." + id + ".region_id");
if(!API.isRegion(region_id))
continue;
if(API.isRegionFull(region_id))
continue;
String name = config.getConfig().getString("attraction." + id + ".name");
Location location = LocationUtils.toLocation(config.getConfig().getString("attraction." + id + ".location"));
Type type = Type.getType(config.getConfig().getString("attraction." + id + ".type"));
Status status = Status.getStatus(config.getConfig().getString("attraction." + id + ".status"));
Attraction attraction = new Attraction(id, name, region_id, location, type, status);
API.addAttraction(attraction);
}
for(Region region : API.getRegions().values())
if(region.getAttractions().isEmpty())
API.removeRegion(region.getId());
}
private static void loadItems() {
if(API.getRegions().values().size() == 0)
return;
gui.clear();
gui.setSize(API.getRegions().size() > 0 ? (API.getRegions().size() * 9) : 9);
for(Region region : API.getRegions().values()) {
if(!index.containsKey(region.getId()))
index.put(region.getId(), index.size() * 9);
int i = index.get(region.getId());
ItemBuilder builder = new ItemBuilder(Material.NAME_TAG);
builder.setName(region.getName());
builder.setLore(region.getLore());
gui.addItem(i, new GUIItem(builder.getItem(), null, true));
}
for(Attraction attraction : API.getAttractions().values()) {
if(!API.isRegion(attraction.getRegion_id())) {
API.removeAttraction(attraction.getId());
continue;
}
if(!index.containsKey(attraction.getRegion_id()))
continue;
int i = index.get(attraction.getRegion_id());
boolean b = false;
for(int a = 1; a < 9; a++) {
if(!gui.hasItem(i + a)) {
i += a;
b = true;
break;
}
}
if(!b) {
API.getRegion(attraction.getRegion_id()).removeAttraction(attraction);
API.removeAttraction(attraction.getId());
continue;
}
ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus()));
builder.setName(attraction.getName());
builder.setLore(StatusManager.getName(attraction.getStatus()));
gui.addItem(i, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
}
}
public static void openMenu(Player player) {
player.openInventory(gui.getInventory());
}
}

View file

@ -0,0 +1,142 @@
package me.paradoxpixel.themepark.attraction.sign;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.LocationUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SignManager {
private static YamlConfig config = ThemeParkPlugin.getInstance().getSigns();
private static HashMap<Attraction, ArrayList<StatusSign>> signs = new HashMap<>();
public static void loadSigns(Attraction attraction) {
if(attraction == null)
return;
if(!config.getConfig().contains("signs." + attraction.getId()))
return;
if(!config.getConfig().isList("signs." + attraction.getId())) {
config.getConfig().set("signs." + attraction.getId(), null);
config.save();
return;
}
ArrayList<StatusSign> array = new ArrayList<>();
List<String> locations = config.getConfig().getStringList("signs." + attraction.getId());
for(String string : locations) {
Location location = LocationUtils.toLocation(string);
if(location == null)
continue;
if(!(location.getBlock().getState() instanceof Sign))
return;
array.add(new StatusSign(attraction, location));
}
signs.put(attraction, array);
}
public static void saveSigns() {
for(Map.Entry<Attraction, ArrayList<StatusSign>> entry : signs.entrySet()) {
List<String> array = new ArrayList<>();
for(StatusSign sign : entry.getValue())
array.add(LocationUtils.toString(sign.getLocation()));
config.getConfig().set("signs." + entry.getKey().getId(), new ArrayList<>());
config.getConfig().set("signs." + entry.getKey().getId(), array);
config.save();
}
}
public static void addSign(StatusSign sign) {
if(sign == null || sign.getLocation() == null)
return;
if(!(sign.getLocation().getBlock().getState() instanceof Sign))
return;
if(signs.containsKey(sign.getAttraction())) {
signs.get(sign.getAttraction()).add(sign);
return;
}
ArrayList<StatusSign> array = new ArrayList<>();
array.add(sign);
signs.put(sign.getAttraction(), array);
}
public static boolean hasSigns(Attraction attraction) {
if(attraction == null)
return false;
return signs.containsKey(attraction) && (signs.get(attraction).size() > 0);
}
public static void update(Attraction attraction) {
if(attraction == null)
return;
if(!hasSigns(attraction))
return;
for(StatusSign sign : signs.get(attraction))
sign.update();
}
public static void remove(Attraction attraction) {
if(attraction == null || !signs.containsKey(attraction))
return;
for(StatusSign sign : signs.get(attraction))
sign.getLocation().getBlock().setType(Material.AIR);
signs.remove(attraction);
config.getConfig().set("signs." + attraction.getId(), null);
config.save();
}
public static void removeSign(StatusSign sign) {
if(sign == null || sign.getLocation() == null || sign.getAttraction() == null)
return;
if(!hasSigns(sign.getAttraction()))
return;
ArrayList<StatusSign> array = signs.get(sign.getAttraction());
for(StatusSign s : new ArrayList<>(array)) {
Location loc1 = sign.getLocation();
Location loc2 = s.getLocation();
if(loc1 == null || loc2 == null)
return;
if(LocationUtils.toString(loc1) == null || LocationUtils.toString(loc2) == null)
return;
if(!LocationUtils.toString(loc1).equals(LocationUtils.toString(loc2)))
return;
array.remove(s);
}
if(array.isEmpty()) {
signs.remove(sign.getAttraction());
config.getConfig().set("signs." + sign.getAttraction().getId(), null);
config.save();
return;
}
signs.put(sign.getAttraction(), array);
}
}

View file

@ -0,0 +1,36 @@
package me.paradoxpixel.themepark.attraction.sign;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Location;
import org.bukkit.block.Sign;
public class StatusSign {
private Attraction attraction;
private Location location;
public StatusSign(Attraction attraction, Location location) {
this.attraction = attraction;
this.location = location;
}
public Attraction getAttraction() {
return attraction;
}
public Location getLocation() {
return location;
}
public void update() {
Status status = attraction.getStatus();
Sign sign = (Sign) location.getBlock().getState();
sign.setLine(2, Utils.color(StatusManager.getName(status)));
sign.update();
}
}

View file

@ -0,0 +1,76 @@
package me.paradoxpixel.themepark.attraction.status;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.config.YamlConfig;
import org.bukkit.Material;
import java.util.HashMap;
public class StatusManager {
private static YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
private static HashMap<Status, String> names;
private static HashMap<Status, Material> materials;
private static HashMap<Status, Short> data;
private static HashMap<Status, Boolean> teleport;
public static void load() {
names = new HashMap<>();
materials = new HashMap<>();
data = new HashMap<>();
teleport = new HashMap<>();
for(Status status : Status.values()) {
if(config.getConfig().contains(status.toString() + ".name")) {
names.put(status, config.getConfig().getString(status.toString() + ".name"));
} else {
names.put(status, "UNKNOWN");
}
if(config.getConfig().contains(status.toString() + ".material")) {
Material material = Material.getMaterial(config.getConfig().getString(status.toString() + ".material"));
if(material == null)
material = Material.STAINED_CLAY;
materials.put(status, material);
} else {
materials.put(status, Material.STAINED_CLAY);
}
if(config.getConfig().contains(status.toString() + ".data")) {
String string = config.getConfig().getString(status.toString() + ".data");
if(string.isEmpty()) {
data.put(status, (short) 0);
continue;
}
data.put(status, Short.parseShort(string));
} else {
data.put(status, (short) 0);
}
if(config.getConfig().contains(status.toString() + ".teleport")) {
teleport.put(status, config.getConfig().getBoolean(status.toString() + ".teleport"));
} else {
teleport.put(status, false);
}
}
}
public static String getName(Status status) {
return names.get(status);
}
public static Material getMaterial(Status status) {
return materials.get(status);
}
public static short getData(Status status) {
return data.get(status);
}
public static boolean canTeleport(Status status) {
return teleport.get(status);
}
}

View file

@ -0,0 +1,25 @@
package me.paradoxpixel.themepark.command;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MenuCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(cmd.getName().equalsIgnoreCase("status")) {
if(sender instanceof Player) {
AttractionMenu.openMenu((Player) sender);
return true;
} else {
sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command"));
}
}
return false;
}
}

View file

@ -0,0 +1,373 @@
package me.paradoxpixel.themepark.command;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.Region;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.ItemBuilder;
import me.paradoxpixel.themepark.utils.Message;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import java.util.Scanner;
import java.util.UUID;
public class ThemeParkCommand extends BukkitCommand {
private String name;
public ThemeParkCommand(String name) {
super(name);
this.name = name;
}
public boolean execute(CommandSender sender,String label, String[] args) {
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
sender.sendMessage(Utils.color("&f/" + name + " help"));
sender.sendMessage(Utils.color("&f/" + name + " list"));
sender.sendMessage(Utils.color("&f/" + name + " warp [id]"));
if(sender.hasPermission("themepark.admin") || sender.hasPermission("themepark.item")) {
sender.sendMessage(Utils.color("&f/" + name + " toggleitem"));
sender.sendMessage(Utils.color("&f/" + name + " getitem"));
}
if(sender.hasPermission("themepark.admin")) {
sender.sendMessage(Utils.color("&f/" + name + " reload"));
sender.sendMessage(Utils.color("&f/" + name + " regionname [id] [name]"));
sender.sendMessage(Utils.color("&f/" + name + " regionlore [id] [index] [lore]"));
sender.sendMessage(Utils.color("&f/" + name + " setlocation [id]"));
sender.sendMessage(Utils.color("&f/" + name + " attraction [id] [status]"));
sender.sendMessage(Utils.color("&f/" + name + " ridecount [id] [player]"));
}
return true;
}
if (args[0].equalsIgnoreCase("list")) {
sender.sendMessage(Utils.color("&f>==== &6ThemePark &f ====<"));
if (API.getAttractions().size() == 0) {
sender.sendMessage(Utils.color(Message.getMessage("attraction.notfound")));
return true;
}
for (Attraction attraction : API.getAttractions().values()) {
String message = Message.getMessage("attraction.list");
message = message.replace("{id}", attraction.getId());
message = message.replace("{name}", attraction.getName());
message = message.replace("{region}", API.getRegion(attraction.getRegion_id()).getName());
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
sender.sendMessage(Utils.color(message));
}
return true;
}
if(args[0].equalsIgnoreCase("warp")) {
if(args.length < 2) {
sender.sendMessage(Utils.color( "&6Themepark&f: &4/" + name + " warp [id]"));
return true;
}
String id = args[1];
if(!API.isAttraction(id)) {
String message = Message.getMessage("attraction.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
if(sender instanceof Player) {
Attraction attraction = API.getAttraction(id);
Player player = (Player) sender;
if(!StatusManager.canTeleport(attraction.getStatus())) {
String message = Message.getMessage("attraction.teleport.status");
message = message.replace("{name}", attraction.getName());
message = message.replace("{status}", StatusManager.getName(attraction.getStatus()));
player.sendMessage(Utils.color(message));
return true;
}
player.teleport(attraction.getLocation());
if(player.isInsideVehicle())
if(player.getVehicle() instanceof Minecart)
return true;
player.sendMessage(Utils.color(Message.getMessage("attraction.teleport.success").replace("{name}", attraction.getName())));
return true;
} else {
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
return true;
}
}
if(!sender.hasPermission("themepark.admin") && !sender.hasPermission("themepark.item")) {
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
return true;
}
if(args[0].equalsIgnoreCase("toggleitem")) {
if(!(sender instanceof Player)) {
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
return true;
}
Player player = (Player) sender;
UUID uuid = player.getUniqueId();
YamlConfig config = ThemeParkPlugin.getInstance().getData();
boolean b = config.getConfig().getBoolean(uuid.toString() + ".item");
b = !b;
config.getConfig().set(uuid.toString() + ".item", b);
config.save();
String message = Message.getMessage("menu.item.toggle");
message = message.replace("{status}", b ? Message.getMessage("enabled") : Message.getMessage("disabled"));
sender.sendMessage(Utils.color(message));
return true;
}
if(args[0].equalsIgnoreCase("getitem")) {
YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
String name = Utils.color(settings.getConfig().getString("item.display-name"));
if(material == null || name.isEmpty())
return true;
Player player;
if(args.length >= 2) {
String string = args[1];
if(Bukkit.getPlayerExact(string) == null) {
String message = Message.getMessage("noplayer");
message = message.replace("{name}", string);
sender.sendMessage(Utils.color(message));
return true;
}
player = Bukkit.getPlayerExact(string);
} else {
if(!(sender instanceof Player)) {
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
return true;
}
player = (Player) sender;
}
ItemBuilder builder = new ItemBuilder(material);
builder.setName(name);
player.getInventory().addItem(builder.getItem());
}
if(!sender.hasPermission("themepark.admin")) {
sender.sendMessage(Utils.color(Message.getMessage("nopermission")));
return true;
}
if(args[0].equalsIgnoreCase("reload")) {
ThemeParkPlugin.getInstance().getData().reload();
ThemeParkPlugin.getInstance().getAttraction().reload();
ThemeParkPlugin.getInstance().getSigns().reload();
ThemeParkPlugin.getInstance().getSettings().reload();
ThemeParkPlugin.getInstance().getMessage().reload();
API.getRegions().clear();
API.getAttractions().clear();
StatusManager.load();
AttractionMenu.load();
for(Region region : API.getRegions().values())
if(region.getAttractions().isEmpty())
API.removeRegion(region.getId());
sender.sendMessage(Utils.color(Message.getMessage("reloaded")));
}
if (args[0].equalsIgnoreCase("regionname")) {
if (args.length < 3) {
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionname [id] [name]"));
return true;
}
String id = args[1];
if (!API.isRegion(id)) {
String message = Message.getMessage("region.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
String name = args[2];
name = name.replaceAll("_", " ");
Region region = API.getRegion(id);
if(region.getName().equals(name))
return true;
region.setName(name);
String message = Message.getMessage("region.changed.name");
message = message.replace("{id}", id);
message = message.replace("{name}", name);
sender.sendMessage(Utils.color(message));
return true;
}
if (args[0].equalsIgnoreCase("regionlore")) {
if (args.length < 4) {
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " regionlore[id] [index] [lore]"));
return true;
}
String id = args[1];
if (!API.isRegion(id)) {
String message = Message.getMessage("region.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
String string = args[2];
if(!isInteger(string)) {
sender.sendMessage(Message.getMessage("nonumber").replace("{number}", string));
return true;
}
int i = Integer.parseInt(string);
String lore = args[3];
lore = lore.replaceAll("_", " ");
Region region = API.getRegion(id);
if(region.getLore().size() > i && region.getLore().get(i).equals(lore))
return true;
region.setLore(i, lore);
String message = Message.getMessage("region.changed.lore");
message = message.replace("{id}", id);
message = message.replace("{index}", "" + i);
message = message.replace("{lore}", lore);
sender.sendMessage(Utils.color(message));
return true;
}
if (args[0].equalsIgnoreCase("setlocation")) {
if (args.length < 2 ) {
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " setlocation [id]"));
return true;
}
String id = args[1];
if(!API.isAttraction(id)) {
String message = Message.getMessage("attraction.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
if(!(sender instanceof Player)) {
sender.sendMessage(Utils.color(Message.getMessage("onlyplayers")));
return true;
}
Attraction attraction = API.getAttraction(id);
attraction.setLocation(((Player) sender).getLocation().clone());
sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName())));
return true;
}
if (args[0].equalsIgnoreCase("attraction")) {
if (args.length < 3 ) {
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " attraction [id] [status]"));
return true;
}
String id = args[1];
if (!API.isAttraction(id)) {
String message = Message.getMessage("attraction.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
Status status = Status.getStatus(args[2]);
if (status == null) {
String message = Message.getMessage("status.no");
message = message.replace("{status}", args[2]);
sender.sendMessage(Utils.color(message));
return true;
}
Attraction attraction = API.getAttraction(id);
if(!attraction.getType().containsStatus(status)) {
String message = Message.getMessage("attraction.nostatus");
message = message.replace("{name}", attraction.getName());
message = message.replace("{status}", status.toString());
sender.sendMessage(Utils.color(message));
return true;
}
if(attraction.getStatus() == status)
return true;
Player player = (sender instanceof Player) ? (Player) sender : null;
attraction.setStatus(status, player);
return true;
}
if (args[0].equalsIgnoreCase("ridecount")) {
if (args.length < 3) {
sender.sendMessage(Utils.color("&6Themepark&f: &4/" + name + " ridecount [id] [player]"));
return true;
}
String id = args[1];
if (!API.isAttraction(id)) {
String message = Message.getMessage("attraction.no");
message = message.replace("{id}", id);
sender.sendMessage(Utils.color(message));
return true;
}
Attraction attraction = API.getAttraction(id);
String string = args[2];
if(Bukkit.getPlayerExact(string) == null) {
String message = Message.getMessage("noplayer");
message = message.replace("{name}", string);
sender.sendMessage(Utils.color(message));
return true;
}
Player player = Bukkit.getPlayerExact(string);
ThemeParkPlugin.getInstance().getDatabaseHandler().addCount(player.getUniqueId(), attraction);
//TODO MESSAGE
return true;
}
return false;
}
private boolean isInteger(String s) {
int radix = 10;
Scanner sc = new Scanner(s.trim());
if(!sc.hasNextInt(radix)) return false;
sc.nextInt(radix);
return !sc.hasNext();
}
}

View file

@ -0,0 +1,87 @@
package me.paradoxpixel.themepark.config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
public class YamlConfig {
private String name;
private File file;
private FileConfiguration config;
private Plugin plugin;
public YamlConfig(String name, Plugin plugin) {
this.name = name.endsWith(".yml") ? name : name + ".yml";
this.plugin = plugin;
load();
}
public void load() {
if(!plugin.getDataFolder().exists())
plugin.getDataFolder().mkdir();
file = new File(plugin.getDataFolder(), name);
if(!file.exists()) {
if(plugin.getResource(name) == null) {
try {
if(!file.createNewFile())
System.out.print("Couldn't create config file: " + name);
} catch(Exception e) {
e.printStackTrace();
return;
}
} else {
plugin.saveResource(name, true);
}
}
config = YamlConfiguration.loadConfiguration(file);
}
public FileConfiguration getConfig() {
return config;
}
public void reload() {
if(file == null) {
load();
return;
}
config = YamlConfiguration.loadConfiguration(file);
}
public void save() {
try {
config.save(file);
} catch(Exception e) {
e.printStackTrace();
}
}
public YamlConfig copy(String name) {
name = name.endsWith(".yml") ? name : name + ".yml";
File file = new File(plugin.getDataFolder(), name);
try {
config.save(file);
} catch(Exception e) {
e.printStackTrace();
return null;
}
return new YamlConfig(name, plugin);
}
public void delete() {
try {
if(!file.delete())
System.out.print("Couldn't delete config file: " + name);
} catch(Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,187 @@
package me.paradoxpixel.themepark.database;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.config.YamlConfig;
import org.bukkit.Bukkit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
public class Database {
public Database(YamlConfig config) {
if(config == null) {
enabled = false;
return;
}
enabled = config.getConfig().getBoolean("mysql.enabled");
host = config.getConfig().getString("mysql.host");
port = config.getConfig().getInt("mysql.port");
database = config.getConfig().getString("mysql.database");
user = config.getConfig().getString("mysql.user");
password = config.getConfig().getString("mysql.password");
}
private boolean enabled;
private String host;
private int port;
private String database;
private String user;
private String password;
private Connection connection;
private int TaskID;
public boolean isEnabled() {
return enabled;
}
public void connect() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
startPool();
} catch(Exception e) {
enabled = false;
e.printStackTrace();
}
}
public void disconnect() {
if(connection == null)
return;
try {
connection.close();
connection = null;
} catch(Exception e) {
e.printStackTrace();
}
}
private boolean connected() {
if(connection == null)
return false;
try {
return !connection.isClosed();
} catch(Exception e) {
e.printStackTrace();
}
return false;
}
private void startPool() {
TaskID = Bukkit.getScheduler().runTaskLater(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
disconnect();
TaskID = 0;
}
}, 1200L).getTaskId();
}
private void stopPool() {
if(TaskID == 0)
return;
Bukkit.getScheduler().cancelTask(TaskID);
TaskID = 0;
}
public boolean execute(String query, HashMap<Integer, Object> objects) {
if(query == null || query.isEmpty())
return false;
if(!enabled)
return false;
if(!connected())
connect();
stopPool();
try {
PreparedStatement statement = connection.prepareStatement(query);
if(objects != null)
for(Map.Entry<Integer, Object> entry : objects.entrySet())
statement.setObject(entry.getKey(), entry.getValue());
boolean b = statement.execute();
statement.close();
startPool();
return b;
} catch(Exception e) {
e.printStackTrace();
}
startPool();
return false;
}
public int executeUpdate(String query, HashMap<Integer, Object> objects) {
if(query == null || query.isEmpty())
return 0;
if(!enabled)
return 0;
if(!connected())
connect();
stopPool();
try {
PreparedStatement statement = connection.prepareStatement(query);
for(Map.Entry<Integer, Object> entry : objects.entrySet())
statement.setObject(entry.getKey(), entry.getValue());
int i = statement.executeUpdate();
statement.close();
startPool();
return i;
} catch(Exception e) {
e.printStackTrace();
}
startPool();
return 0;
}
public ResultSet executeQuery(String query, HashMap<Integer, Object> objects) {
if(query == null || query.isEmpty())
return null;
if(!enabled)
return null;
if(!connected())
connect();
stopPool();
try {
PreparedStatement statement = connection.prepareStatement(query);
for(Map.Entry<Integer, Object> entry : objects.entrySet())
statement.setObject(entry.getKey(), entry.getValue());
ResultSet result = statement.executeQuery();
statement.close();
startPool();
return result;
} catch(Exception e) {
e.printStackTrace();
}
startPool();
return null;
}
}

View file

@ -0,0 +1,117 @@
package me.paradoxpixel.themepark.database;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.Region;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
public class DatabaseHandler {
private Database database;
public DatabaseHandler(YamlConfig config) {
database = new Database(config);
load();
}
private void load() {
database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null);
database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null);
database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null);
database.execute("CREATE TABLE IF NOT EXISTS ridecount (uuid VARCHAR(256) NOT NULL, attractionId VARCHAR(256) NOT NULL, date VARCHAR(256), count INT(11) NOT NULL)", null);
database.execute("TRUNCATE TABLE attraction", null);
database.execute("TRUNCATE TABLE region", null);
database.execute("TRUNCATE TABLE status", null);
for(Attraction attraction : API.getAttractions().values())
addAttraction(attraction);
for(Region region : API.getRegions().values())
addRegion(region);
for(Status status : Status.values()) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, status.toString());
objects.put(2, StatusManager.getName(status));
database.execute("INSERT INTO status (statusId,statusName) VALUES(?,?)", objects);
}
}
public void addAttraction(Attraction attraction) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, attraction.getId());
objects.put(2, attraction.getName());
objects.put(3, attraction.getRegion_id());
objects.put(4, attraction.getType().toString());
objects.put(5, attraction.getStatus().toString());
database.execute("INSERT IGNORE INTO attraction(id, name, region_id, type, status) VALUES (?,?,?,?,?)", objects);
}
public void updateAttraction(Attraction attraction) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, attraction.getStatus().toString());
objects.put(2, attraction.getId());
database.execute("UPDATE attraction SET status=? WHERE id=?", objects);
}
public void removeAttraction(Attraction attraction) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, attraction.getId());
database.execute("DELETE FROM attraction WHERE id=?", objects);
database.execute("DELETE FROM ridecount WHERE attractionId=?", objects);
}
public void addRegion(Region region) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, region.getId());
objects.put(2, region.getName());
database.execute("INSERT IGNORE INTO region(id, name) VALUES (?,?)", objects);
}
public void updateRegion(Region region) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, region.getName());
objects.put(2, region.getId());
database.execute("UPDATE region SET name=? WHERE id=?", objects);
}
public void removeRegion(Region region) {
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, region.getId());
database.execute("DELETE FROM region WHERE id=?", objects);
}
public void addCount(UUID uuid, Attraction attraction) {
String pattern = "dd-MM-yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String date = simpleDateFormat.format(new Date());
HashMap<Integer, Object> objects = new HashMap<>();
objects.put(1, uuid.toString());
objects.put(2, attraction.getId());
objects.put(3, date);
if(database.executeUpdate("UPDATE ridecount SET count=count+1 WHERE uuid=? AND attractionId=? AND date=?", objects) < 1) {
database.execute("INSERT INTO ridecount(uuid,attractionId,date,count) VALUES (?,?,?,1)", objects);
}
}
public void disconnect() {
database.disconnect();
}
}

View file

@ -0,0 +1,120 @@
package me.paradoxpixel.themepark.gui;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class GUI extends GUIHolder {
private String title;
private int size;
private Inventory inventory;
private HashMap<Integer, GUIItem> items = new HashMap<>();
public GUI(String title, int size) {
if(size > 54)
size = 54;
this.title = title;
this.size = Utils.toSize(size, 9);
inventory = Bukkit.createInventory(this, this.size, Utils.color(title));
}
private void update() {
ArrayList<Integer> toRemove = new ArrayList<>();
for(Map.Entry<Integer, GUIItem> entry : items.entrySet()) {
if(entry.getKey() >= getSize()) {
toRemove.add(entry.getKey());
continue;
}
inventory.setItem(entry.getKey(), entry.getValue().getItem());
}
for(int i : toRemove)
items.remove(i);
}
public void setSize(int size) {
if(size > 54)
size = 54;
this.size = Utils.toSize(size, 9);
inventory = Bukkit.createInventory(this, this.size, Utils.color(title));
update();
}
public int getSize() {
return size;
}
public void clear() {
inventory = Bukkit.createInventory(this, Utils.toSize(size, 9), Utils.color(title));
items.clear();
}
public void addItems(HashMap<Integer, GUIItem> items) {
for(Map.Entry<Integer, GUIItem> entry : items.entrySet())
addItem(entry.getKey(), entry.getValue());
}
public void addItem(int slot, GUIItem item) {
if(slot >= getSize() || slot < 0)
return;
items.put(slot, item);
inventory.setItem(slot, item.getItem());
}
public void removeItem(int slot) {
items.remove(slot);
}
public void switchSlot(int from, int to) {
if(!items.containsKey(from))
return;
GUIItem item = items.get(from);
items.put(to, item);
items.remove(from);
}
public boolean hasItem(int slot) {
return items.containsKey(slot);
}
@Override
public boolean execute(Player player, int slot, ClickType type) {
if(player == null || slot >= getSize() || slot < 0 || type == null)
return false;
if(!items.containsKey(slot))
return false;
GUIItem item = items.get(slot);
if(type == ClickType.RIGHT) {
if(item.getActionRight() != null)
item.getActionRight().click(player);
return item.hasCancelRight();
} else {
if(item.getActionLeft() != null)
item.getActionLeft().click(player);
return item.hasCancelLeft();
}
}
@Override
public Inventory getInventory() {
return inventory;
}
}

View file

@ -0,0 +1,9 @@
package me.paradoxpixel.themepark.gui;
import org.bukkit.entity.Player;
public abstract class GUIAction {
public abstract void click(Player player);
}

View file

@ -0,0 +1,11 @@
package me.paradoxpixel.themepark.gui;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.InventoryHolder;
public abstract class GUIHolder implements InventoryHolder {
public abstract boolean execute(Player player, int slot, ClickType type);
}

View file

@ -0,0 +1,45 @@
package me.paradoxpixel.themepark.gui;
import org.bukkit.inventory.ItemStack;
public class GUIItem {
private ItemStack item;
private GUIAction aleft, aright;
private boolean cleft, cright;
public GUIItem(ItemStack item, GUIAction action, boolean cancel) {
this.item = item;
aleft = aright = action;
cleft = cright = cancel;
}
public GUIItem(ItemStack item, GUIAction aleft, GUIAction aright, boolean cleft, boolean cright) {
this.item = item;
this.aleft = aleft;
this.aright = aright;
this.cleft = cleft;
this.cright = cright;
}
public ItemStack getItem() {
return item;
}
public boolean hasCancelLeft() {
return cleft;
}
public boolean hasCancelRight() {
return cright;
}
public GUIAction getActionLeft() {
return aleft;
}
public GUIAction getActionRight() {
return aright;
}
}

View file

@ -0,0 +1,29 @@
package me.paradoxpixel.themepark.gui;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
public class GUIListener implements Listener {
@EventHandler
public void onClick(InventoryClickEvent e) {
if(e.getClickedInventory() == null)
return;
Inventory inventory = e.getClickedInventory();
if(!(inventory.getHolder() instanceof GUIHolder))
return;
Player player = (Player) e.getWhoClicked();
int slot = e.getRawSlot();
ClickType type = e.getClick();
GUI gui = (GUI) inventory.getHolder();
e.setCancelled(gui.execute(player, slot, type));
}
}

View file

@ -0,0 +1,115 @@
package me.paradoxpixel.themepark.listener;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.api.event.attraction.AddAttractionEvent;
import me.paradoxpixel.themepark.api.event.attraction.RemoveAttractionEvent;
import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent;
import me.paradoxpixel.themepark.api.event.region.AddRegionEvent;
import me.paradoxpixel.themepark.api.event.region.ChangeRegionEvent;
import me.paradoxpixel.themepark.api.event.region.RemoveRegionEvent;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.attraction.sign.SignManager;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.Message;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ChangeListener implements Listener {
@EventHandler
public void onChange(StatusChangeEvent e) {
AttractionMenu.reload();
SignManager.update(e.getAttraction());
Attraction attraction = e.getAttraction();
Status status = e.getStatusAfter();
String message = Message.getMessage("attraction.changed.status." + status.toString());
message = message.replace("{name}", attraction.getName());
message = message.replace("{status}", StatusManager.getName(status));
Bukkit.broadcastMessage(Utils.color(message));
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().updateAttraction(e.getAttraction());
}
});
}
@EventHandler
public void onChange(AddAttractionEvent e) {
AttractionMenu.reload();
SignManager.loadSigns(e.getAttraction());
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().addAttraction(e.getAttraction());
}
});
}
@EventHandler
public void onChange(RemoveAttractionEvent e) {
AttractionMenu.reload();
SignManager.remove(e.getAttraction());
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
config.getConfig().set("attraction." + e.getAttraction().getId(), null);
config.save();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().removeAttraction(e.getAttraction());
}
});
}
@EventHandler
public void onChange(AddRegionEvent e) {
AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().addRegion(e.getRegion());
}
});
}
@EventHandler
public void onChange(ChangeRegionEvent e) {
AttractionMenu.reload();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().updateRegion(e.getRegion());
}
});
}
@EventHandler
public void onChange(RemoveRegionEvent e) {
AttractionMenu.reload();
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
config.getConfig().set("region." + e.getRegion().getId(), null);
config.save();
Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(), new Runnable() {
@Override
public void run() {
ThemeParkPlugin.getInstance().getDatabaseHandler().removeRegion(e.getRegion());
}
});
}
}

View file

@ -0,0 +1,45 @@
package me.paradoxpixel.themepark.listener;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class ClickListener implements Listener {
private YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
@EventHandler
public void onInteract(PlayerInteractEvent e) {
Material material = Material.getMaterial(config.getConfig().getString("item.material"));
String name = Utils.color(config.getConfig().getString("item.display-name"));
if(e.getItem() == null)
return;
ItemStack item = e.getItem();
if(item.getType() != material)
return;
if(!item.hasItemMeta())
return;
if(!item.getItemMeta().getDisplayName().equals(name))
return;
if(e.getAction() == Action.LEFT_CLICK_AIR ||
e.getAction() == Action.LEFT_CLICK_BLOCK)
return;
e.setCancelled(true);
Player player = e.getPlayer();
AttractionMenu.openMenu(player);
}
}

View file

@ -0,0 +1,68 @@
package me.paradoxpixel.themepark.listener;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.database.DatabaseHandler;
import me.paradoxpixel.themepark.utils.ItemBuilder;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Material;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class PlayerListener implements Listener {
private YamlConfig config = ThemeParkPlugin.getInstance().getData();
private YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Material material = Material.getMaterial(settings.getConfig().getString("item.material"));
String name = Utils.color(settings.getConfig().getString("item.display-name"));
int slot = settings.getConfig().getInt("item.slot");
if(material == null || name.isEmpty())
return;
Player player = e.getPlayer();
boolean b = true;
if(config.getConfig().contains(player.getUniqueId().toString() + ".item")) {
b = config.getConfig().getBoolean(player.getUniqueId().toString() + ".item");
} else {
config.getConfig().set(player.getUniqueId().toString() + ".item", true);
config.save();
}
if(b) {
ItemBuilder builder = new ItemBuilder(material);
builder.setName(name);
if(settings.getConfig().getBoolean("inventory.clear"))
player.getInventory().clear();
player.getInventory().setItem(slot, builder.getItem());
}
}
@EventHandler
public void onTeleport(PlayerTeleportEvent e) {
Player player = e.getPlayer();
if(e.getCause() != PlayerTeleportEvent.TeleportCause.PLUGIN)
return;
if(!player.isInsideVehicle())
return;
if(player.getVehicle() == null)
return;
if(!(player.getVehicle() instanceof Minecart))
return;
e.setCancelled(true);
player.sendMessage(Utils.color("&6ThemePark&f: &4You can't teleport while in a minecart"));
}
}

View file

@ -0,0 +1,64 @@
package me.paradoxpixel.themepark.listener;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
import me.paradoxpixel.themepark.attraction.sign.SignManager;
import me.paradoxpixel.themepark.attraction.sign.StatusSign;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;
public class SignListener implements Listener {
private YamlConfig config = ThemeParkPlugin.getInstance().getSettings();
private String name = config.getConfig().getString("sign.name");
private String title = config.getConfig().getString("sign.title");
@EventHandler
public void onPlace(SignChangeEvent e) {
if(!e.getLine(0).equalsIgnoreCase(name))
return;
String id = e.getLine(1);
if(id == null || id.isEmpty() || !API.isAttraction(id))
return;
Attraction attraction = API.getAttraction(id);
e.setLine(0, Utils.color(title));
e.setLine(1, Utils.color(attraction.getName()));
e.setLine(2, Utils.color(StatusManager.getName(attraction.getStatus())));
Location location = e.getBlock().getLocation();
StatusSign statusSign = new StatusSign(attraction, location);
SignManager.addSign(statusSign);
}
@EventHandler
public void onBreak(BlockBreakEvent e) {
if(e.getBlock() == null)
return;
Block block = e.getBlock();
if(!(block.getState() instanceof Sign))
return;
Sign sign = (Sign) block.getState();
if(!sign.getLine(0).equals(Utils.color(title)))
return;
Attraction attraction = API.getAttractionFromName(sign.getLine(1));
Location location = e.getBlock().getLocation();
StatusSign s = new StatusSign(attraction, location);
SignManager.removeSign(s);
}
}

View file

@ -0,0 +1,111 @@
package me.paradoxpixel.themepark.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class ItemBuilder {
private ItemStack item;
public ItemBuilder(ItemStack item) {
this.item = item;
}
public ItemBuilder(Material material) {
item = new ItemStack(material, 1);
}
public ItemBuilder(Material material, int amount) {
item = new ItemStack(material, amount);
}
public ItemBuilder(Material material, int amount, short data) {
item = new ItemStack(material, amount, data);
}
public ItemStack getItem() {
return item;
}
public ItemBuilder setDurability(short durability) {
item.setDurability(durability);
return this;
}
public ItemBuilder setName(String name) {
if(name == null)
return this;
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Utils.color(name));
this.item.setItemMeta(meta);
return this;
}
public ItemBuilder setLore(List<String> lore) {
if(lore == null)
return this;
ItemMeta meta = item.getItemMeta();
for(String string : lore)
lore.set(lore.indexOf(string), Utils.color(string));
meta.setLore(lore);
item.setItemMeta(meta);
return this;
}
public ItemBuilder setLore(String lore) {
List<String> list = new ArrayList<>();
list.add(lore);
setLore(list);
return this;
}
public ItemBuilder addLore(String lore) {
List<String> list = item.getItemMeta().getLore();
list.add(lore);
setLore(list);
return this;
}
public ItemBuilder setEnchantment(HashMap<Enchantment, Integer> enchantments) {
ItemMeta meta = item.getItemMeta();
if(!meta.getEnchants().isEmpty())
meta.getEnchants().clear();
for(Map.Entry<Enchantment, Integer> entry : enchantments.entrySet())
meta.addEnchant(entry.getKey(), entry.getValue(), true);
item.setItemMeta(meta);
return this;
}
public ItemBuilder setEnchantment(Enchantment enchantment, int i) {
ItemMeta meta = item.getItemMeta();
if (!meta.getEnchants().isEmpty())
meta.getEnchants().clear();
meta.addEnchant(enchantment, i, true);
item.setItemMeta(meta);
return this;
}
public ItemBuilder addEnchantment(Enchantment enchantment, int i) {
ItemMeta meta = item.getItemMeta();
meta.addEnchant(enchantment, i, true);
item.setItemMeta(meta);
return this;
}
public ItemBuilder clone() {
return new ItemBuilder(item);
}
}

View file

@ -0,0 +1,50 @@
package me.paradoxpixel.themepark.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
public class LocationUtils {
public static String toString(Location location) {
if(location == null)
return null;
World world = location.getWorld();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String string = world.getName() + ":" + x + ":" + y + ":" + z;
if(location.getYaw() != 0 || location.getPitch() != 0)
string += ":" + location.getYaw() + ":" + location.getPitch();
return string;
}
public static Location toLocation(String string) {
if(string == null)
return null;
String[] args = string.split(":");
if(args.length < 4)
return null;
World world = Bukkit.getWorld(args[0]);
double x = Double.parseDouble(args[1]);
double y = Double.parseDouble(args[2]);
double z = Double.parseDouble(args[3]);
Location location = new Location(world, x, y, z);
if(args.length < 6)
return location;
float yaw = Float.parseFloat(args[4]);
float pitch = Float.parseFloat(args[5]);
location.setYaw(yaw);
location.setPitch(pitch);
return location;
}
}

View file

@ -0,0 +1,25 @@
package me.paradoxpixel.themepark.utils;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.config.YamlConfig;
public class Message {
private static YamlConfig config = ThemeParkPlugin.getInstance().getMessage();
public static boolean isMessage(String string) {
return config.getConfig().contains(string);
}
public static String getMessage(String string) {
if(!isMessage(string))
return "";
String message = config.getConfig().getString(string);
if(isMessage("prefix"))
message = message.replace("{prefix}", config.getConfig().getString("prefix"));
return message;
}
}

View file

@ -0,0 +1,15 @@
package me.paradoxpixel.themepark.utils;
import org.bukkit.ChatColor;
public class Utils {
public static String color(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
public static int toSize(int i, int size) {
return i % size == 0 ? i : i + (size - (i % size));
}
}

View file

@ -0,0 +1,40 @@
region:
global:
name: "&5Global"
lore:
- "&5Global Locations"
fantasy:
name: "&aFantasy"
lore:
- "&aFantasy Themed rides"
multiple:
name: "&fMultiple"
lore:
- "&fYou can have"
- "&fMultiple lines"
- "&fWith Lore"
attraction:
ride1:
name: "&aRide #1"
region_id: "fantasy"
type: RIDE
status: CLOSED
location: "world:0:0:0"
show1:
name: "&aFirst Show"
region_id: "fantasy"
type: SHOW
status: INACTIVE
location: "world:0:0:0"
global1:
name: "&aFirst Global"
region_id: "global"
type: GLOBAL
location: "world:0:0:0"
random:
name: "&fRandom"
type: RIDE
status: CLOSED
region_id: multiple
location: "world:0:0:0"

View file

@ -0,0 +1,42 @@
prefix: "&6Themepark&f:"
onlyplayers: "{prefix} &4Only players can use this command"
nopermission: "{prefix} &4You don't have permission to use this command"
noplayer: "{prefix} &4No player found with name: {name}"
nonumber: "&6Themepark&f: &4{number} &4is not a valid number"
reloaded: "{prefix} &aThe plugin has been reloaded"
menu:
item:
enabled: "&aENABLED"
disabled: "&4DISABLED"
toggle: "{prefix} &aMenu item has been {status}"
region:
no: "{prefix} &4There is no region with ID: {id}"
changed:
name: "{prefix} &aChanged the name tho: {name} &aFor region: {id}"
lore: "{prefix} &aChanged the lore with index &f{index} &ato: {lore} &afor region: &f{id}"
status:
no: "{prefix} &4There is no status named: {status}"
attraction:
notfound: "&4No attractions found"
list: "&6ID: &f{id} &6Name: &f{name} &6Region: &f{region} &6Status: &f{status}"
no: "{prefix} &4There is no attraction with ID: {id}"
nostatus: "{prefix} &4Attraction: {name} &4has no status named: {status}"
changed:
status:
CONSTRUCTION: "{prefix} &fAttraction: {name} &fis now &7Under Construction"
OPEN: "{prefix} &fAttraction: {name} &fhas been &aOpened"
CLOSED: "{prefix} &fAttraction: {name} &fhas been &4Closed"
MAINTENANCE: "{prefix} &fAttraction: {name} &fis now in &6Maintenance"
MALFUNCTION: "{prefix} &fAttraction: {name} &fhas been closed due to a &5Malfunction"
ACTIVE: "{prefix} &fShow: {name} &fis now &aActive"
INACTIVE: "{prefix} &fShow: {name} &fis now &4In Active"
location: "&6ThemePark&f: &aChanged locatation of attraction: {name} &ato your current location"
teleport:
status: "{prefix} &4It's not possible to teleport to {name} &4because it's {status}"
success: "{prefix} &ayou have been teleported to the attraction: {name}"

View file

@ -0,0 +1,6 @@
name: ThemePark
version: 1.1
main: me.paradoxpixel.themepark.ThemeParkPlugin
author: ParadoxPixel
commands:
status:

View file

@ -0,0 +1,72 @@
command: 'themepark'
sign:
name: "[ThemePark]"
title: "&f[&6ThemePark&f]"
menu:
title: "&6StatusMenu"
inventory:
clear: true
item:
material: NETHER_STAR
display-name: 'Themepark'
slot: 4
mysql:
enabled: false
host: 'localhost'
port: 3306
database: 'database'
user: 'username'
password: 'password'
CONSTRUCTION:
name: "&7Under Construction"
material: STAINED_CLAY
data: 1
teleport: false
OPEN:
name: "&aOpen"
material: STAINED_CLAY
data: 5
teleport: true
CLOSED:
name: "&4Closed"
material: STAINED_CLAY
data: 14
teleport: true
MAINTENANCE:
name: "&6Maintenance"
material: STAINED_CLAY
data: 4
teleport: true
MALFUNCTION:
name: "&5Malfunction"
material: STAINED_CLAY
data: 10
teleport: true
ACTIVE:
name: "&aActive"
material: STAINED_CLAY
data: 5
teleport: true
INACTIVE:
name: "&4In Active"
material: STAINED_CLAY
data: 14
teleport: true
GLOBAL:
name: "&bGlobal"
material: STAINED_CLAY
data: 11
teleport: true