3
0
Fork 0

Big Update

This commit is contained in:
BuildTools 2020-04-18 21:46:53 +02:00
parent ceafeebede
commit 6b85ced40b
15 changed files with 248 additions and 142 deletions

View file

@ -7,6 +7,7 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="themepark" />
<module name="ThemePark" />
</profile>
</annotationProcessing>
</component>

12
pom.xml
View file

@ -11,13 +11,17 @@
<groupId>me.paradoxpixel</groupId>
<artifactId>themepark</artifactId>
<version>1.3.1</version>
<version>1.4.1</version>
<repositories>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>dynmap</id>
<url>http://repo.mikeprimm.com/</url>
</repository>
</repositories>
<dependencies>
@ -28,9 +32,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.2</version>
<groupId>org.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -12,7 +12,6 @@ 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 me.paradoxpixel.themepark.placeholder.ThemeParkPlaceholder;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.PluginManager;
@ -46,9 +45,6 @@ public class ThemeParkPlugin extends JavaPlugin {
private void loadData() {
StatusManager.load();
AttractionMenu.load();
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new ThemeParkPlaceholder(this).register();
}
}
private void loadDatabase() {

View file

@ -0,0 +1,20 @@
package me.paradoxpixel.themepark.action;
import me.paradoxpixel.themepark.attraction.AttractionMenu;
import me.paradoxpixel.themepark.gui.GUIAction;
import org.bukkit.entity.Player;
public class PageAction extends GUIAction {
private int page;
public PageAction(int page) {
this.page = page;
}
@Override
public void click(Player player) {
AttractionMenu.openMenu(player, page);
}
}

View file

@ -21,9 +21,6 @@ public class API {
if(isRegion(region.getId()))
return;
if(regions.size() >= 6)
return;
region = toLower(region);
regions.put(region.getId(), region);

View file

@ -1,6 +1,7 @@
package me.paradoxpixel.themepark.attraction;
import me.paradoxpixel.themepark.ThemeParkPlugin;
import me.paradoxpixel.themepark.action.PageAction;
import me.paradoxpixel.themepark.action.TPUtils;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.Attraction;
@ -13,26 +14,39 @@ import me.paradoxpixel.themepark.gui.GUI;
import me.paradoxpixel.themepark.gui.GUIItem;
import me.paradoxpixel.themepark.utils.ItemBuilder;
import me.paradoxpixel.themepark.api.LocationUtils;
import me.paradoxpixel.themepark.utils.Utils;
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;
import java.util.Set;
public class AttractionMenu {
private static YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings();
private static GUI gui;
private static HashMap<Integer, GUI> pages = new HashMap<>();
private static boolean loading = false;
private static String title;
private static HashMap<String, Integer> index;
private static HashMap<String, Integer> regionPage;
private static HashMap<String, Integer> attractionIndex;
private static Material mat = Material.NAME_TAG;
private static short data = 0;
public static void load() {
loading = true;
gui = new GUI(settings.getConfig().getString("menu.title"), 9);
index = new HashMap<>();
title = settings.getConfig().getString("menu.title");
mat = Material.getMaterial(settings.getConfig().getString("region.material"));
data = Short.parseShort(settings.getConfig().getString("region.data"));
regionPage = new HashMap<>();
attractionIndex = new HashMap<>();
loadData();
loading = false;
loadItems();
@ -73,11 +87,6 @@ public class AttractionMenu {
HashMap<String, Region> regions = API.getRegions();
HashMap<String, Integer> size = new HashMap<>();
for(String id : section.getKeys(false)) {
if(size.size() >= 6) {
config.getConfig().set("regions." + id, null);
continue;
}
String name = config.getConfig().getString("region." + id + ".name");
List<String> lore = config.getConfig().getStringList("region." + id + ".lore");
@ -91,7 +100,6 @@ public class AttractionMenu {
Region region = new Region(id, name, lore);
API.addRegion(region);
if(!id.toLowerCase().equals(id)) {
config.getConfig().set("region." + id, null);
id = id.toLowerCase();
@ -101,10 +109,10 @@ public class AttractionMenu {
}
config.save();
for(String string : regions.keySet())
API.removeRegion(string);
prepareGUI();
if(!config.getConfig().contains("attraction"))
return;
@ -150,12 +158,13 @@ public class AttractionMenu {
attraction.setLocation(location);
attraction.setType(type);
attraction.setStatus(status, null);
MapMarker.getMarker().setAttractionMarker(attraction);
continue;
}
Attraction attraction = new Attraction(id, name, region_id, location, type, status);
API.addAttraction(attraction);
MapMarker.getMarker().setAttractionMarker(attraction);
if(!id.toLowerCase().equals(id)) {
config.getConfig().set("attraction." + id, null);
id = id.toLowerCase();
@ -167,11 +176,83 @@ public class AttractionMenu {
}
config.save();
for(String string : attractions.keySet())
API.removeAttraction(string);
}
private static void prepareGUI() {
int keySize = API.getRegions().size();
if(pages.isEmpty()) {
if(keySize <= 6) {
pages.put(1, new GUI(title, keySize * 9));
} else {
int p = keySize / 5;
for(int i = 0; i < p; i++)
pages.put(i + 1, new GUI(title, 54));
int rest = keySize % 5;
if(rest > 0)
pages.put(p + 1, new GUI(title, rest * 9 + 9));
}
} else {
if(keySize <= 6) {
if(pages.size() > 1) {
for(int i = 1; i < pages.size(); i++)
pages.remove(i + 1);
}
int z = keySize*9;
GUI gui = pages.get(1);
if(gui.getSize() != z)
gui.setSize(z);
} else {
int p = keySize / 5;
int rest = keySize % 5;
if (rest > 0)
p++;
if (pages.size() < p) {
for (int i = (pages.size() + 1); i < p; i++)
pages.put(i, new GUI(title, 54));
pages.put(p, new GUI(title, rest * 9 + 9));
} else {
if (pages.size() > p) {
for (int i = pages.size(); i > p; i--)
pages.remove(i);
} else {
if(rest != 0) {
pages.get(p).setSize(rest * 9 + 9);
} else {
pages.get(p).setSize(54);
}
}
}
}
}
}
public static void update(Attraction attraction) {
if(attraction == null)
return;
if(!API.isAttraction(attraction.getId()))
return;
if(!attractionIndex.containsKey(attraction.getId()))
return;
if(!regionPage.containsKey(attraction.getRegion_id()))
return;
ItemBuilder builder = new ItemBuilder(StatusManager.getMaterial(attraction.getStatus()), 1, StatusManager.getData(attraction.getStatus()));
builder.setName(attraction.getName());
builder.setLore(StatusManager.getName(attraction.getStatus()));
GUI gui = pages.get(regionPage.get(attraction.getRegion_id()));
gui.addItem(attractionIndex.get(attraction.getId()), new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
}
private static void loadItems() {
if(loading)
return;
@ -179,20 +260,34 @@ public class AttractionMenu {
if(API.getRegions().values().size() == 0)
return;
gui.clear();
gui.setSize(API.getRegions().size() > 0 ? (API.getRegions().size() * 9) : 9);
for(GUI gui : pages.values())
gui.clear();
int i = 1;
int j = 0;
boolean tb = pages.size() > 1;
HashMap<String, Integer> index = new HashMap<>();
for(Region region : API.getRegions().values()) {
if(tb && j >= 5) {
i++;
j = 0;
}
index.put(region.getId(), j * 9);
regionPage.put(region.getId(), i);
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);
ItemBuilder builder = new ItemBuilder(mat, 1, data);
builder.setName(region.getName());
builder.setLore(region.getLore());
gui.addItem(i, new GUIItem(builder.getItem(), null, true));
GUI gui = pages.get(i);
gui.addItem(j * 9, new GUIItem(builder.getItem(), null, true));
j++;
}
for(Attraction attraction : API.getAttractions().values()) {
if(!API.isRegion(attraction.getRegion_id())) {
API.removeAttraction(attraction.getId());
@ -202,11 +297,12 @@ public class AttractionMenu {
if(!index.containsKey(attraction.getRegion_id()))
continue;
int i = index.get(attraction.getRegion_id());
int in = index.get(attraction.getRegion_id());
GUI gui = pages.get(regionPage.get(attraction.getRegion_id()));
boolean b = false;
for(int a = 1; a < 9; a++) {
if(!gui.hasItem(i + a)) {
i += a;
if(!gui.hasItem(in + a)) {
in += a;
b = true;
break;
}
@ -221,12 +317,43 @@ public class AttractionMenu {
builder.setName(attraction.getName());
builder.setLore(StatusManager.getName(attraction.getStatus()));
gui.addItem(i, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
gui.addItem(in, new GUIItem(builder.getItem(), new TPUtils(attraction.getId()), true));
attractionIndex.put(attraction.getId(), in);
}
if(pages.size() <= 1)
return;
i = 1;
for(GUI gui : pages.values()) {
int rows = gui.getSize() / 9;
int offset = (rows - 1) * 9;
if(i > 1) {
ItemBuilder previous = new ItemBuilder(Material.ARROW);
previous.setName(Utils.color("&6Previous"));
gui.addItem(offset + 3, new GUIItem(previous.getItem(), new PageAction(i - 1), true));
}
ItemBuilder middle = new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 1);
middle.setName(Utils.color("&6Page: "+i));
gui.addItem(offset + 4, new GUIItem(middle.getItem(), null, true));
if(i < pages.size()) {
ItemBuilder next = new ItemBuilder(Material.ARROW);
next.setName(Utils.color("&6Next"));
gui.addItem(offset + 5, new GUIItem(next.getItem(), new PageAction(i + 1), true));
}
i++;
}
}
public static void openMenu(Player player) {
player.openInventory(gui.getInventory());
public static void openMenu(Player player, int page) {
if(page < 1 || page > pages.size())
page = 1;
player.openInventory(pages.get(page).getInventory());
}
}

View file

@ -27,10 +27,14 @@ public class StatusSign {
public void update() {
Status status = attraction.getStatus();
if(!location.getChunk().isLoaded())
location.getChunk().load();
if(!(location.getBlock().getState() instanceof Sign)) {
SignManager.removeSign(this);
return;
}
Sign sign = (Sign) location.getBlock().getState();
sign.setLine(2, Utils.color(StatusManager.getName(status)));
sign.update();

View file

@ -13,7 +13,7 @@ public class MenuCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(cmd.getName().equalsIgnoreCase("status")) {
if(sender instanceof Player) {
AttractionMenu.openMenu((Player) sender);
AttractionMenu.openMenu((Player) sender, 1);
return true;
} else {
sender.sendMessage(Utils.color("&6Themepark&f: &4Only players can use this command"));

View file

@ -7,6 +7,7 @@ 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.MapMarker;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
import me.paradoxpixel.themepark.utils.ItemBuilder;
@ -290,6 +291,7 @@ public class ThemeParkCommand extends BukkitCommand {
Attraction attraction = API.getAttraction(id);
attraction.setLocation(location.clone());
MapMarker.getMarker().setAttractionMarker(attraction);
sender.sendMessage(Utils.color(Message.getMessage("attraction.location").replace("{name}", attraction.getName())));
return true;
}

View file

@ -10,6 +10,7 @@ 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.MapMarker;
import me.paradoxpixel.themepark.attraction.sign.SignManager;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.config.YamlConfig;
@ -26,10 +27,11 @@ public class ChangeListener implements Listener {
if(e.getAttraction() == null)
return;
AttractionMenu.reload();
SignManager.update(e.getAttraction());
Attraction attraction = e.getAttraction();
AttractionMenu.update(attraction);
Status status = e.getStatusAfter();
String message = Message.getMessage("attraction.changed.status." + status.toString());
message = message.replace("{name}", attraction.getName());
@ -56,6 +58,7 @@ public class ChangeListener implements Listener {
AttractionMenu.reload();
SignManager.remove(e.getAttraction());
MapMarker.getMarker().removeAttractionMarker(e.getAttraction());
YamlConfig config = ThemeParkPlugin.getInstance().getAttraction();
config.getConfig().set("attraction." + e.getAttraction().getId(), null);
config.save();

View file

@ -39,7 +39,7 @@ public class ClickListener implements Listener {
e.setCancelled(true);
Player player = e.getPlayer();
AttractionMenu.openMenu(player);
AttractionMenu.openMenu(player, 1);
}
}

View file

@ -10,8 +10,12 @@ 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.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class PlayerListener implements Listener {
@ -20,30 +24,12 @@ public class PlayerListener implements Listener {
@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;
doItem(e.getPlayer());
}
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 onSwitch(PlayerChangedWorldEvent e) {
doItem(e.getPlayer());
}
@EventHandler
@ -65,4 +51,40 @@ public class PlayerListener implements Listener {
player.sendMessage(Utils.color("&6ThemePark&f: &4You can't teleport while in a minecart"));
}
public void doItem(Player player) {
if(!settings.getConfig().getBoolean("item.enabled"))
return;
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;
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) {
if(settings.getConfig().getBoolean("inventory.clear"))
player.getInventory().clear();
List<String> worlds = settings.getConfig().getStringList("item.worlds");
if(worlds != null && !worlds.isEmpty()) {
if (worlds.contains(player.getLocation().getWorld().getName())) {
player.getInventory().setItem(slot, new ItemStack(Material.AIR));
return;
}
}
ItemBuilder builder = new ItemBuilder(material);
builder.setName(name);
player.getInventory().setItem(slot, builder.getItem());
}
}
}

View file

@ -1,78 +0,0 @@
package me.paradoxpixel.themepark.placeholder;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.paradoxpixel.themepark.api.API;
import me.paradoxpixel.themepark.api.attraction.component.Status;
import me.paradoxpixel.themepark.attraction.status.StatusManager;
import me.paradoxpixel.themepark.utils.Utils;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
public class ThemeParkPlaceholder extends PlaceholderExpansion {
private Plugin plugin;
public ThemeParkPlaceholder(Plugin plugin){
this.plugin = plugin;
}
@Override
public boolean persist(){
return true;
}
@Override
public boolean canRegister() {
return true;
}
@Override
public String getAuthor() {
return "ParadoxPixel";
}
@Override
public String getIdentifier() {
return "tp";
}
@Override
public String getVersion() {
return plugin.getDescription().getVersion();
}
@Override
public String onRequest(OfflinePlayer player, String identifier){
if(identifier == null || player == null)
return "";
if(identifier.startsWith("status")) {
String[] args = identifier.split(":");
if(args.length < 2)
return "";
String id = args[1];
if(!API.isAttraction(id))
return "";
Status status = API.getAttraction(id).getStatus();
return Utils.color(StatusManager.getName(status));
}
if(identifier.startsWith("name")) {
String[] args = identifier.split(":");
if(args.length < 2)
return "";
String id = args[1];
if(!API.isAttraction(id))
return "";
String name = API.getAttraction(id).getName();
return Utils.color(name);
}
return "";
}
}

View file

@ -1,7 +1,7 @@
name: ThemePark
version: 1.3.1
version: 1.4.1
main: me.paradoxpixel.themepark.ThemeParkPlugin
author: ParadoxPixel
softdepend: [PlaceholderAPI]
softdepend: [PlaceholderAPI,Dynmap]
commands:
status:

View file

@ -11,9 +11,13 @@ inventory:
clear: true
item:
enabled: true
material: NETHER_STAR
display-name: 'Themepark'
slot: 4
worlds:
- world_nether
- world_the_end
mysql:
enabled: false
@ -24,6 +28,10 @@ mysql:
password: 'password'
url: 'jdbc:mysql://%host%:%port%/%database%?useSSL=false'
region:
material: NAME_TAG
data: 0
CONSTRUCTION:
name: "&7Under Construction"
material: STAINED_CLAY