hi
This commit is contained in:
commit
7244cdbc85
11
.classpath
Normal file
11
.classpath
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Jack Barry/Desktop/Zyrox Test Server/plugins/WorldEdit.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Jack Barry/Desktop/Zyrox Test Server/mSpigotUpdated.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Jack Barry/Desktop/Jar libs/FeatherBoard.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Jack Barry/Desktop/Zyrox Test Server/plugins/worldguard 6.1.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Jack Barry/Desktop/Zyrox Test Server/plugins/FastAsyncWorldEdit-bukkit-18.09.25-934897f-1217-21.5.4.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
bin/
|
||||
out/
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
InvadedLands PlayerWarps.iml
|
8
.idea/artifacts/PlayerWarps.xml
generated
Normal file
8
.idea/artifacts/PlayerWarps.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" build-on-make="true" name="PlayerWarps">
|
||||
<output-path>$PROJECT_DIR$/out</output-path>
|
||||
<root id="archive" name="PlayerWarps.jar">
|
||||
<element id="module-output" name="InvadedLands PlayerWarps" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="8" />
|
||||
</component>
|
||||
</project>
|
6
.idea/discord.xml
generated
Normal file
6
.idea/discord.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="true" />
|
||||
</component>
|
||||
</project>
|
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/str/playerwarps/util/RandomStringGenerator.java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
11
.idea/misc.xml
generated
Normal file
11
.idea/misc.xml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/InvadedLands PlayerWarps.iml" filepath="$PROJECT_DIR$/InvadedLands PlayerWarps.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>InvadedLands PlayerWarps</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
44
InvadedLands PlayerWarps.iml
Normal file
44
InvadedLands PlayerWarps.iml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="EclipseModuleManager">
|
||||
<libelement value="jar://$USER_HOME$/Desktop/Zyrox Test Server/plugins/WorldEdit.jar!/" />
|
||||
<libelement value="jar://$USER_HOME$/Desktop/Zyrox Test Server/mSpigotUpdated.jar!/" />
|
||||
<libelement value="file://D:/Zyrox and Shield/FeatherBoard.jar" />
|
||||
<libelement value="jar://$USER_HOME$/Desktop/Zyrox Test Server/plugins/worldguard 6.1.jar!/" />
|
||||
<libelement value="jar://$USER_HOME$/Desktop/Zyrox Test Server/plugins/FastAsyncWorldEdit-bukkit-18.09.25-934897f-1217-21.5.4.jar!/" />
|
||||
<src_description expected_position="1">
|
||||
<src_folder value="file://$MODULE_DIR$/src" expected_position="1" />
|
||||
</src_description>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/bin" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="file://$MODULE_DIR$/../../dependencies" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$MODULE_DIR$/../../dependencies" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$MODULE_DIR$/../../dependencies" recursive="false" />
|
||||
<jarDirectory url="file://$MODULE_DIR$/../../dependencies" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
0
src/config.yml
Normal file
0
src/config.yml
Normal file
22
src/data.yml
Normal file
22
src/data.yml
Normal file
@ -0,0 +1,22 @@
|
||||
#PlaceHolders
|
||||
# Duped-WarpCreate-Punishment: %player% - player being punished, %id% warpcreate ID.
|
||||
|
||||
Warps-Created-By:
|
||||
|
||||
Saved-Blocks:
|
||||
|
||||
Blocked-Items:
|
||||
|
||||
Blocked-Warp-Wall-Items:
|
||||
|
||||
Main-world: "world"
|
||||
|
||||
Server-name: "&6&lServerName"
|
||||
|
||||
WarpCreateBlock-Use-Region: "spawn"
|
||||
|
||||
AntiFly-Region: "spawn"
|
||||
|
||||
Duped-WarpCreate-Punishment: "blacklist %player% &cUsage of duplicated warpcreate ID: %id%."
|
||||
|
||||
WarpSort:
|
14
src/plugin.yml
Normal file
14
src/plugin.yml
Normal file
@ -0,0 +1,14 @@
|
||||
name: PlayerWarps
|
||||
main: str.playerwarps.PlayerWarps
|
||||
version: Build-15
|
||||
author: StarZorrow
|
||||
description: Creation of PlayerWarps like InvadedLands
|
||||
softdepend: [WorldEdit, WorldGuard, Multiverse-core, FastAsyncWorldEdit]
|
||||
commands:
|
||||
warpcreate:
|
||||
description: "Main command for PlayerWarps."
|
||||
warpcreateblock:
|
||||
description: "Give physical playerwarp creation blocks to players."
|
||||
pw:
|
||||
aliases: [playerwarps, playerwarp, pwarp]
|
||||
description: "PlayerWarp command GUI."
|
289
src/str/playerwarps/PlayerWarps.java
Normal file
289
src/str/playerwarps/PlayerWarps.java
Normal file
@ -0,0 +1,289 @@
|
||||
package str.playerwarps;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
import str.playerwarps.commands.Commands;
|
||||
import str.playerwarps.commands.gui.GUI;
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
import str.playerwarps.gui.types.PaginatedGUIAllPages;
|
||||
import str.playerwarps.gui.types.PaginatedGUICP;
|
||||
import str.playerwarps.listener.InventoryListener;
|
||||
import str.playerwarps.listener.PlayerListener;
|
||||
import str.playerwarps.listener.WarpBlockListener;
|
||||
import str.playerwarps.listener.WorldListener;
|
||||
import str.playerwarps.setup.WarpBox;
|
||||
import str.playerwarps.util.Utils;
|
||||
import str.playerwarps.util.Zone;
|
||||
|
||||
public class PlayerWarps extends JavaPlugin implements Listener {
|
||||
|
||||
public static PlayerWarps plugin;
|
||||
public static WarpBox wb;
|
||||
public static WarpBlockListener wbl;
|
||||
public static WorldListener wl;
|
||||
public static GUI gui;
|
||||
private File dataFile;
|
||||
private FileConfiguration data;
|
||||
public static List<String> warpsort;
|
||||
public boolean featherBoardHook = false;
|
||||
private boolean depend1, depend2, depend3 = true;
|
||||
public static Location nextLocation = new Location(Bukkit.getWorld("PlayerWarps-World"), -10000, 0, 0);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
gui = new GUI();
|
||||
System.out.println("[PlayerWarps] Loading Config");
|
||||
createCustomData();
|
||||
System.out.println("[PlayerWarps] Loaded Config");
|
||||
System.out.println("[PlayerWarps] Registering Events");
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
PaginatedGUI.prepare(this);
|
||||
PaginatedGUIAllPages.prepare(this);
|
||||
PaginatedGUICP.prepare(this);
|
||||
if (isFeatherBoardPresent()) {
|
||||
setfeatherBoardHook(true);
|
||||
Utils.sendConsoleMessage("&a[PlayerWarps] Featherboard support enabled");
|
||||
}
|
||||
else {
|
||||
setfeatherBoardHook(false);
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Featherboard not found, disabling support");
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core") != null) {
|
||||
Utils.sendConsoleMessage("&a[PlayerWarps] Dependencies found: Multiverse-Core");
|
||||
}
|
||||
else {
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Dependencies not found: Multiverse-Core");
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Disabling plugin as required dependencies not found!");
|
||||
onDisable();
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
Utils.sendConsoleMessage("&a[PlayerWarps] Dependencies found: WorldEdit");
|
||||
}
|
||||
else {
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Dependencies not found: WorldEdit");
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Disabling plugin as required dependencies not found!");
|
||||
onDisable();
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
Utils.sendConsoleMessage("&a[PlayerWarps] Dependencies found: WorldGuard");
|
||||
}
|
||||
else {
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Dependencies not found: WorldGuard");
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Disabling plugin as required dependencies not found!");
|
||||
onDisable();
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null) {
|
||||
Utils.sendConsoleMessage("&a[PlayerWarps] Dependencies found: FastAsyncWorldEdit");
|
||||
}
|
||||
else {
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Dependencies not found: FastAsyncWorldEdit");
|
||||
Utils.sendConsoleMessage("&c[PlayerWarps] Disabling plugin as required dependencies not found!");
|
||||
onDisable();
|
||||
return;
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new WarpBlockListener(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new WarpBox(), this);
|
||||
System.out.println("[PlayerWarps] Loading Variables");
|
||||
wb = new WarpBox();
|
||||
wl = new WorldListener();
|
||||
System.out.println("[PlayerWarps] Loaded Variables");
|
||||
System.out.println("[PlayerWarps] Loaded Events");
|
||||
System.out.println("[PlayerWarps] Registering Commands");
|
||||
getCommand("warpcreate").setExecutor(new Commands(this));
|
||||
getCommand("warpcreateblock").setExecutor(new Commands(this));
|
||||
getCommand("pw").setExecutor(new GUI());
|
||||
// getCommand("pwgui").setExecutor(new GUI());
|
||||
System.out.println("[PlayerWarps] Loaded Commands");
|
||||
System.out.println("[PlayerWarps] Loading Cache");
|
||||
if (getCustomData().getConfigurationSection("Saved-Blocks") != null) {
|
||||
for (String key : getCustomData().getConfigurationSection("Saved-Blocks").getKeys(false)) {
|
||||
wbl.placedBlock.add(new Location(Bukkit.getWorld(getCustomData().getString("Saved-Blocks." + key + ".world")), getCustomData().getInt("Saved-Blocks." + key + ".x"), getCustomData().getInt("Saved-Blocks." + key + ".y"), getCustomData().getInt("Saved-Blocks." + key + ".z")));
|
||||
}
|
||||
}
|
||||
// if (getCustomData().getConfigurationSection("Saved-Walls") != null) {
|
||||
// for (String key : getCustomData().getConfigurationSection("Saved-Walls").getKeys(false)) {
|
||||
// wbl.walls.add(new Location(Bukkit.getWorld(getCustomData().getString("Saved-Walls." + key + ".world")), getCustomData().getInt("Saved-Walls." + key + ".x"), getCustomData().getInt("Saved-Walls." + key + ".y"), getCustomData().getInt("Saved-Walls." + key + ".z")));
|
||||
// }
|
||||
// }
|
||||
warpsort = (List<String>) getCustomData().getStringList("WarpSort");
|
||||
if (getCustomData().get("guiRefreshRateInSeconds") == null) {
|
||||
getCustomData().set("guiRefreshRateInSeconds", 5);
|
||||
saveConfig();
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null && Bukkit.getWorld("PlayerWarps-World") != null) {
|
||||
BukkitScheduler scheduler = getServer().getScheduler();
|
||||
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
warpsort.clear();
|
||||
Set<String> set = getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
warpsort.add(sort + " - " + uuid.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(warpsort, Collections.reverseOrder());
|
||||
if (getCustomData().getStringList("WarpList") == null) {
|
||||
getCustomData().set("WarpSort", warpsort);
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
else {
|
||||
getCustomData().set("WarpSort", null);
|
||||
getCustomData().set("WarpSort", warpsort);
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
}
|
||||
}, 20l, (long)(20 * getCustomData().getLong("guiRefreshRateInSeconds")));
|
||||
}
|
||||
loadNextLocation();
|
||||
System.out.println("[PlayerWarps] Loaded Cache");
|
||||
System.out.println("[PlayerWarps] Loading FilterList");
|
||||
// InventoryListener.addFilterList();
|
||||
System.out.println("[PlayerWarps] Loaded FilterList");
|
||||
System.out.println("[PlayerWarps] Enabled");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
getCustomData().set("nextXLocation", nextLocation.getX());
|
||||
saveConfig();
|
||||
int i = 0;
|
||||
for (Location loc : wbl.placedBlock) {
|
||||
i++;
|
||||
getCustomData().set("Saved-Blocks." + i + ".x", loc.getX());
|
||||
getCustomData().set("Saved-Blocks." + i + ".y", loc.getY());
|
||||
getCustomData().set("Saved-Blocks." + i + ".z", loc.getZ());
|
||||
getCustomData().set("Saved-Blocks." + i + ".world", loc.getWorld().getName());
|
||||
}
|
||||
saveConfig();
|
||||
|
||||
System.out.println("[PlayerWarps] Disabled");
|
||||
}
|
||||
|
||||
public boolean getFeatherboardSupport() {
|
||||
return featherBoardHook;
|
||||
}
|
||||
|
||||
public void loadNextLocation() {
|
||||
if (getCustomData().contains("nextXLocation")) {
|
||||
double x = getCustomData().getDouble("nextXLocation");
|
||||
nextLocation = new Location(Bukkit.getWorld("PlayerWarps-World"), x, 0, 0);
|
||||
}
|
||||
else {
|
||||
getCustomData().set("nextXLocation", nextLocation.getX());
|
||||
saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getCustomData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
private void createCustomData() {
|
||||
dataFile = new File(getDataFolder(), "data.yml");
|
||||
if (!dataFile.exists()) {
|
||||
dataFile.getParentFile().mkdirs();
|
||||
saveResource("data.yml", false);
|
||||
}
|
||||
|
||||
data = new YamlConfiguration();
|
||||
try {
|
||||
data.load(dataFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerWarps get() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static WarpBox getWarpBox() {
|
||||
return wb;
|
||||
}
|
||||
|
||||
public static WorldListener getWorldSetup() {
|
||||
return wl;
|
||||
}
|
||||
|
||||
public static WarpBlockListener getWarpBlock() {
|
||||
return wbl;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
this.data.save(this.dataFile);
|
||||
} catch (IOException e) {
|
||||
getLogger().warning("Unable to save data.yml");
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
this.data = YamlConfiguration.loadConfiguration(this.dataFile);
|
||||
}
|
||||
|
||||
private boolean isFeatherBoardPresent() {
|
||||
if (getServer().getPluginManager().getPlugin("FeatherBoard") == null) {
|
||||
setfeatherBoardHook(false);
|
||||
return featherBoardHook;
|
||||
}
|
||||
if (getServer().getPluginManager().getPlugin("FeatherBoard").isEnabled()) {
|
||||
setfeatherBoardHook(true);
|
||||
}
|
||||
|
||||
return featherBoardHook;
|
||||
}
|
||||
|
||||
private void setfeatherBoardHook(boolean a) {
|
||||
featherBoardHook = a;
|
||||
}
|
||||
}
|
778
src/str/playerwarps/commands/Commands.java
Normal file
778
src/str/playerwarps/commands/Commands.java
Normal file
@ -0,0 +1,778 @@
|
||||
package str.playerwarps.commands;
|
||||
|
||||
import org.bukkit.event.*;
|
||||
import str.playerwarps.*;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.*;
|
||||
import str.playerwarps.listener.*;
|
||||
import java.text.*;
|
||||
import org.bukkit.potion.*;
|
||||
import org.apache.commons.lang.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import str.playerwarps.util.*;
|
||||
import java.util.regex.*;
|
||||
import org.bukkit.*;
|
||||
import java.util.*;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
|
||||
public class Commands implements CommandExecutor, Listener
|
||||
{
|
||||
static PlayerWarps plugin;
|
||||
public static ArrayList<String> warpqueue;
|
||||
private String help;
|
||||
private String usageWC;
|
||||
private String usageWCB;
|
||||
private static String noPerms;
|
||||
|
||||
public Commands(final PlayerWarps instance) {
|
||||
this.help = "&e=== &6WarpCreate Help-Menu &e===";
|
||||
this.usageWC = "&eUsage: &f/&ewarpcreate &6<create, delete, fix, approve, approveconfirm, warpqueue, commandAdd, commandDel, reload> &e(warpqueue-page-#) (command) &e(<10m, 20m, 30m, 90m>) (<player>).";
|
||||
this.usageWCB = "&eUsage: &f/&ewarpcreateblock &6giveBlock <10m, 20m, 30m, 90m> <player>&e.";
|
||||
Commands.plugin = instance;
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
if (cmd.getName().equalsIgnoreCase("warpcreate")) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
Utils.sendConsoleMessage("&cYou cannot use this command in console.");
|
||||
}
|
||||
else if (!sender.hasPermission("core.warpcreates")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
if (args.length == 0) {
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("core.warpcreates.reload")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
PlayerWarps.get().reloadConfig();
|
||||
Utils.sendMessage(sender, "&aSuccessfully reloaded PlayerWarps.");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("warpqueue")) {
|
||||
if (sender.hasPermission("core.warpcreate.warpqueue")) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
return false;
|
||||
}
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("create")) {
|
||||
if (!sender.hasPermission("core.warpcreates.create")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete")) {
|
||||
if (!sender.hasPermission("core.warpcreates.delete")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("fix")) {
|
||||
if (!sender.hasPermission("core.warpcreates.fix")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
if (!sender.hasPermission("core.warpcreates.create")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (args[1] != null) {
|
||||
if (!args[2].equalsIgnoreCase("h") && !args[2].equalsIgnoreCase("m") && !args[2].equalsIgnoreCase("s")) {
|
||||
Utils.sendMessage(sender, "&cYou can only use 1 time span in warpcreation.");
|
||||
return false;
|
||||
}
|
||||
final Player target = Bukkit.getPlayer(args[3].toString());
|
||||
final Player player = (Player)sender;
|
||||
if (target != null) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
final Pattern pattern = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match = pattern.matcher(args[1]);
|
||||
final boolean found = match.find();
|
||||
if (found) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time = 0;
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("s")) {
|
||||
time = Integer.parseInt(args[1]);
|
||||
}
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.createWarp(target);
|
||||
final Date now = new Date();
|
||||
final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
Utils.saveEditTime(target.getUniqueId().toString(), time, "(+" + args[1] + args[2] + ") " + format.format(now), "true");
|
||||
Utils.sendMessage(sender, "&eYou've successfully added &6" + args[1] + args[2] + " &eof edit time to &6" + target.getName() + "'s warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&6" + args[1] + args[2] + " &eof edit time has been successfully added to your warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&eYou may start editing your warp by accessing the &6control panel &eblock at your warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&eTo go to your warp issue the follow command: &6/pw " + target.getName());
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&cYou cannot add edit time to &6" + target.getName() + "'s &cwarp as they are building.");
|
||||
}
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target.getUniqueId().toString()) == null) {
|
||||
final Pattern pattern = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match = pattern.matcher(args[1]);
|
||||
final boolean found = match.find();
|
||||
if (found) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time = 0;
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("s")) {
|
||||
time = Integer.parseInt(args[1]);
|
||||
}
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.createWarp(target);
|
||||
final Date now = new Date();
|
||||
final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
Utils.saveEditTime(target.getUniqueId().toString(), time, "(+" + args[1] + args[2] + ") " + format.format(now), "true");
|
||||
Utils.sendMessage(sender, "&eYou've successfully &a&lcreated &eand added &6" + args[1] + args[2] + " &eof edit time to &6" + target.getName() + "'s warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&eYour warp has successfully been &a&lcreated &eand &6" + args[1] + args[2] + " &eof edit time has been added to your warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&eYou may start editing your warp by accessing the &6control panel &eblock at your warp.");
|
||||
Utils.sendMessage((CommandSender)target, "&eTo go to your warp issue the follow command: &6/pw " + target.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
final OfflinePlayer target2 = Bukkit.getOfflinePlayer(args[3].toString());
|
||||
if (target2 == null) {
|
||||
Utils.sendMessage(sender, "&cError: This player has never joined the server");
|
||||
return false;
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target2.getUniqueId().toString()) != null) {
|
||||
final Pattern pattern2 = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match2 = pattern2.matcher(args[1]);
|
||||
final boolean found2 = match2.find();
|
||||
if (found2) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time2 = 0;
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time2 = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time2 = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("s")) {
|
||||
time2 = Integer.parseInt(args[1]);
|
||||
}
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.createWarp(target);
|
||||
final Date now2 = new Date();
|
||||
final SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
Utils.saveEditTime(target2.getUniqueId().toString(), time2, "(+" + args[1] + args[2] + ") " + format2.format(now2), "true");
|
||||
Utils.sendMessage(sender, "&eYou've successfully added &6" + args[1] + args[2] + " &eof edit time to &6" + target2.getName() + "'s warp.");
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target2.getUniqueId().toString()) == null) {
|
||||
final Pattern pattern2 = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match2 = pattern2.matcher(args[1]);
|
||||
final boolean found2 = match2.find();
|
||||
if (found2) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time2 = 0;
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time2 = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time2 = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("s")) {
|
||||
time2 = Integer.parseInt(args[1]);
|
||||
}
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.createWarp(target);
|
||||
final Date now2 = new Date();
|
||||
final SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
Utils.saveEditTime(target2.getUniqueId().toString(), time2, "(+" + args[1] + args[2] + ") " + format2.format(now2), "true");
|
||||
Utils.sendMessage(sender, "&eYou've successfully &a&lcreated &eand added &6" + args[1] + args[2] + " &eof edit time to &6" + target2.getName() + "'s warp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu(sender);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu(sender);
|
||||
}
|
||||
}
|
||||
else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("warpqueue")) {
|
||||
if (sender.hasPermission("core.warpcreate.warpqueue")) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
return false;
|
||||
}
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
this.helpMenu(sender);
|
||||
}
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
if (!sender.hasPermission("core.warpcreates.create")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("commandDel")) {
|
||||
if (!sender.hasPermission("core.warpcreates.commandDel")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("commandAdd")) {
|
||||
if (!sender.hasPermission("core.warpcreates.commandAdd")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
return false;
|
||||
}
|
||||
this.helpMenu(sender);
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete")) {
|
||||
if (!sender.hasPermission("core.warpcreates.delete")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
final Player target = Bukkit.getPlayer(args[1]);
|
||||
final Player player = (Player)sender;
|
||||
if (target != null) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target.getUniqueId().toString()) != null) {
|
||||
Utils.removeWarp(target.getUniqueId().toString());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
if (Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world")) != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
target.teleport(Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world")).getSpawnLocation());
|
||||
target.setGameMode(GameMode.SURVIVAL);
|
||||
target.getInventory().clear();
|
||||
for (final PotionEffect effects : target.getActivePotionEffects()) {
|
||||
target.removePotionEffect(effects.getType());
|
||||
}
|
||||
}
|
||||
Utils.sendMessage(sender, "&6" + target.getName() + "'s &eplayerwarp has been deleted!");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
final OfflinePlayer target2 = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target2.getUniqueId().toString()) != null) {
|
||||
Utils.removeWarp(target2.getUniqueId().toString());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
Utils.sendMessage(sender, "&6" + target2.getName() + "'s &eplayerwarp has been deleted!");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target2.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("fix")) {
|
||||
if (!sender.hasPermission("core.warpcreates.fix")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
final Player target = Bukkit.getPlayer(args[1]);
|
||||
final Player player = (Player)sender;
|
||||
if (target != null) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target.getUniqueId().toString()) != null) {
|
||||
Utils.fixWarp(target.getUniqueId().toString());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
if (Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world")) != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
target.teleport(Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world")).getSpawnLocation());
|
||||
target.setGameMode(GameMode.SURVIVAL);
|
||||
target.getInventory().clear();
|
||||
for (final PotionEffect effects : target.getActivePotionEffects()) {
|
||||
target.removePotionEffect(effects.getType());
|
||||
}
|
||||
}
|
||||
Utils.sendMessage(sender, "&6" + target.getName() + "'s &eplayerwarp was put in ready to build state (Fixed if broken)!");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
final OfflinePlayer target2 = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target2.getUniqueId().toString()) != null) {
|
||||
Utils.fixWarp(target2.getUniqueId().toString());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
Utils.sendMessage(sender, "&6" + target2.getName() + "'s &eplayerwarp was put in ready to build state (Fixed if broken)!");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target2.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("warpqueue")) {
|
||||
if (!sender.hasPermission("core.warpcreates.warpqueue")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
final ArrayList<String> warpqueue = new ArrayList<String>();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") == null) {
|
||||
Utils.sendMessage(sender, "&eThere are no &6warps &ein queue for &6approval&e.");
|
||||
return false;
|
||||
}
|
||||
int count = 0;
|
||||
final Set<String> set = (Set<String>)PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
final Iterator<String> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
final UUID uuid = UUID.fromString(it.next());
|
||||
final OfflinePlayer target3 = Bukkit.getOfflinePlayer(uuid);
|
||||
final Player player2 = (Player)sender;
|
||||
if ((target3.hasPlayedBefore() || target3 != null) && PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + uuid.toString()) != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target3.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval").equalsIgnoreCase("true")) {
|
||||
warpqueue.add(target3.getName());
|
||||
}
|
||||
else {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false).size() == count) {
|
||||
Utils.sendMessage(sender, "&eThere are no &6warps &ein queue for &6approval&e.");
|
||||
return false;
|
||||
}
|
||||
final Pattern pattern2 = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match2 = pattern2.matcher(args[1]);
|
||||
final boolean found2 = match2.find();
|
||||
if (found2) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eShowing all results for &3PlayerWarps &eneeding approval: ");
|
||||
Utils.paginate(sender, warpqueue, Integer.parseInt(args[1]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("approve")) {
|
||||
if (!sender.hasPermission("core.warpcreates.approve")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
final OfflinePlayer target4 = Bukkit.getOfflinePlayer(args[1]);
|
||||
final Player player = (Player)sender;
|
||||
if (target4.hasPlayedBefore() || target4 != null) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target4.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Approved") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Approved").equalsIgnoreCase("false")) {
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.approveVoidWorld(player, target4);
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + "'s &eplayerwarp is already approved.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + "'s &eplayerwarp cannot be approved while they are building.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("approveconfirm")) {
|
||||
if (!sender.hasPermission("core.warpcreates.approve")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else {
|
||||
final OfflinePlayer target4 = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + target4.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Approved") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Approved").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Need-Approval") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target4.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("true")) {
|
||||
PlayerWarps.getWorldSetup();
|
||||
if (WorldListener.ready.containsKey(target4)) {
|
||||
PlayerWarps.getWorldSetup();
|
||||
WorldListener.approveConfirmVoidWorld(target4, false);
|
||||
Utils.sendMessage(sender, "&eYou have confirmed approval of &6" + target4.getName() + "'s &eplayerwarp!");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eYou cannot confirm approval for &6" + target4.getName() + "'s &eplayerwarp as no one has looked at it:");
|
||||
Utils.sendMessage(sender, "&f/&ewarpcreate approve &6" + target4.getName());
|
||||
}
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + "'s &eplayerwarp is not ready yet.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + "'s &eplayerwarp is already approved.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + "'s &eplayerwarp cannot be approved while they are building.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + target4.getName() + " &edoesn't have a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu(sender);
|
||||
}
|
||||
}
|
||||
else if (args.length >= 1) {
|
||||
if (args[0].equals("commandAdd")) {
|
||||
if (!sender.hasPermission("core.warpcreates.commandAdd")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (args.length >= 1) {
|
||||
if (sender instanceof Player) {
|
||||
String command = "";
|
||||
for (int i = 1; i < args.length; ++i) {
|
||||
final String arg = args[i] + " ";
|
||||
command += arg;
|
||||
}
|
||||
final Player p = (Player)sender;
|
||||
if (PlayerWarps.get().getCustomData().getStringList("command-whitelist").contains(StringUtils.chop(command))) {
|
||||
p.sendMessage(Utils.replace("&6" + command + "&eis already whitelisted"));
|
||||
}
|
||||
else {
|
||||
final List<String> commands = (List<String>)PlayerWarps.get().getCustomData().getStringList("command-whitelist");
|
||||
commands.add(StringUtils.chop(command));
|
||||
PlayerWarps.get().getCustomData().set("command-whitelist", (Object)commands);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
p.sendMessage(Utils.replace("&6" + command + "&ehas been added to the command whitelist"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Utils.replace("&eOnly players can execute that command"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Utils.replace("&ePlease specify a command to whitelist"));
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("commandDel")) {
|
||||
if (!sender.hasPermission("core.warpcreates.commandDel")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (args.length >= 1) {
|
||||
if (sender instanceof Player) {
|
||||
String command = "";
|
||||
for (int i = 1; i < args.length; ++i) {
|
||||
final String arg = args[i] + " ";
|
||||
command += arg.toLowerCase();
|
||||
}
|
||||
final Player p = (Player)sender;
|
||||
if (!PlayerWarps.get().getCustomData().getStringList("command-whitelist").contains(StringUtils.chop(command))) {
|
||||
p.sendMessage(Utils.replace("&6" + command + "&ewasn't already whitelisted"));
|
||||
}
|
||||
else {
|
||||
final List<String> commands = (List<String>)PlayerWarps.get().getCustomData().getStringList("command-whitelist");
|
||||
commands.remove(StringUtils.chop(command));
|
||||
PlayerWarps.get().getCustomData().set("command-whitelist", (Object)commands);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
p.sendMessage(Utils.replace("&6" + command + "&ehas been removed from the command whitelist"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Utils.replace("&eOnly players can execute that command"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Utils.replace("&ePlease specify a command to unwhitelist"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cmd.getName().equalsIgnoreCase("warpcreateblock")) {
|
||||
if (!sender.hasPermission("core.warpcreates.giveblock")) {
|
||||
Utils.sendMessage(sender, Commands.noPerms);
|
||||
}
|
||||
else if (sender instanceof ConsoleCommandSender) {
|
||||
if (args.length == 0) {
|
||||
this.helpMenu2Console();
|
||||
}
|
||||
else if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("giveBlock")) {
|
||||
if (args[1] != null) {
|
||||
if (args[2].equalsIgnoreCase("h") || args[2].equalsIgnoreCase("m") || args[2].equalsIgnoreCase("s")) {
|
||||
final Player target = Bukkit.getPlayer(args[3].toString());
|
||||
if (target != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
Utils.sendConsoleMessage("&6" + target.getName() + " &ccannot be given this item as they're building a warp already.");
|
||||
}
|
||||
else {
|
||||
final Pattern pattern3 = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match3 = pattern3.matcher(args[1]);
|
||||
final boolean found3 = match3.find();
|
||||
if (found3) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time3 = 0;
|
||||
final String timelength = "" + args[1] + "" + args[2];
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time3 = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time3 = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("s")) {
|
||||
time3 = Integer.parseInt(args[1]);
|
||||
}
|
||||
final List<String> wclore = new ArrayList<String>();
|
||||
ItemStack wcblock = new ItemStack(Material.LAPIS_BLOCK);
|
||||
final ItemMeta im = wcblock.getItemMeta();
|
||||
wclore.add(Utils.replace("&3This is a WarpCreate."));
|
||||
wclore.add(Utils.replace("&3WarpCreates allow the player with"));
|
||||
wclore.add(Utils.replace("&3this item to create a PlayerWarp."));
|
||||
wclore.add(Utils.replace("&3This will clear your inventory so put away any other items."));
|
||||
wclore.add(Utils.replace("&7[&eRight-Click this to create a " + timelength + " WarpCreate&7]"));
|
||||
im.setDisplayName(Utils.replace("&3WarpCreate &7[&3" + timelength + "&7]"));
|
||||
im.setLore((List)wclore);
|
||||
wcblock.setItemMeta(im);
|
||||
final String antiDupe = RandomStringGenerator.randomString(35, true, true, false);
|
||||
wcblock = ItemMetadata.setMetadata(wcblock, "AntiDupe", antiDupe);
|
||||
target.getInventory().addItem(new ItemStack[] { ItemMetadata.setMetadata(wcblock, "WarpCreate", timelength) });
|
||||
Utils.sendConsoleMessage("&eYou have given a &3" + timelength + " &eWarpCreate &eto &6" + target.getName() + " &e.");
|
||||
Utils.sendMessage((CommandSender)target, "&eYou have been given a &3" + timelength + " &eWarpCreate &eto &6" + target.getName() + " &e.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + args[3].toString() + " &eis not online.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&cYou can only use 1 time span in warpcreation.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2Console();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2Console();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2Console();
|
||||
}
|
||||
}
|
||||
else if (sender instanceof Player) {
|
||||
if (args.length == 0) {
|
||||
this.helpMenu2(sender);
|
||||
}
|
||||
else if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("giveBlock")) {
|
||||
if (args[1] != null) {
|
||||
if (args[2].equalsIgnoreCase("h") || args[2].equalsIgnoreCase("m") || args[2].equalsIgnoreCase("s")) {
|
||||
final Player target = Bukkit.getPlayer(args[3].toString());
|
||||
final Player player = (Player)sender;
|
||||
if (target != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + target.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
Utils.sendMessage(sender, "&6" + target.getName() + "&ccannot be given this item as they're building a warp already.");
|
||||
}
|
||||
else {
|
||||
final Pattern pattern = Pattern.compile("[^0-9 ]");
|
||||
final Matcher match = pattern.matcher(args[1]);
|
||||
final boolean found = match.find();
|
||||
if (found) {
|
||||
Utils.sendMessage(sender, "&cError: the time is not alphabetic nor symbolized.");
|
||||
return false;
|
||||
}
|
||||
int time = 0;
|
||||
final String timelength2 = "" + args[1] + "" + args[2];
|
||||
if (args[2].equalsIgnoreCase("h")) {
|
||||
time = Integer.parseInt(args[1]) * 3600;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("m")) {
|
||||
time = Integer.parseInt(args[1]) * 60;
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("s")) {
|
||||
time = Integer.parseInt(args[1]);
|
||||
}
|
||||
final List<String> wclore2 = new ArrayList<String>();
|
||||
ItemStack wcblock2 = new ItemStack(Material.LAPIS_BLOCK);
|
||||
final ItemMeta im2 = wcblock2.getItemMeta();
|
||||
im2.setDisplayName(Utils.replace("&3WarpCreate &7[&3" + timelength2 + "&7]"));
|
||||
wclore2.add(Utils.replace("&3This is a WarpCreate."));
|
||||
wclore2.add(Utils.replace("&3WarpCreates allow the player with"));
|
||||
wclore2.add(Utils.replace("&3this item to create a PlayerWarp."));
|
||||
wclore2.add(Utils.replace("&3This will clear your inventory so put away any other items."));
|
||||
wclore2.add(Utils.replace("&7[&eRight-Click this to create a " + timelength2 + " WarpCreate&7]"));
|
||||
im2.setLore((List)wclore2);
|
||||
wcblock2.setItemMeta(im2);
|
||||
final String antiDupe2 = RandomStringGenerator.randomString(35, true, true, false);
|
||||
wcblock2 = ItemMetadata.setMetadata(wcblock2, "AntiDupe", antiDupe2);
|
||||
target.getInventory().addItem(new ItemStack[] { ItemMetadata.setMetadata(wcblock2, "WarpCreate", timelength2) });
|
||||
Utils.sendMessage(sender, "&eYou have given a &3" + timelength2 + " &eWarpCreate &eto &6" + target.getName() + " &e.");
|
||||
Utils.sendMessage((CommandSender)target, "&eYou have been given a &3" + timelength2 + " &eWarpCreate &eto &6" + target.getName() + " &e.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&6" + args[3].toString() + " &eis not online.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&cYou can only use 1 time span in warpcreation.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2(sender);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2(sender);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.helpMenu2(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void helpMenu(final CommandSender player) {
|
||||
final List<String> helpMenu = new ArrayList<String>();
|
||||
int count = 0;
|
||||
helpMenu.add(Utils.replace(this.help));
|
||||
if (player.hasPermission("core.warpcreates.create")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate create <time> <time-span> <player-name> &e- &3Example: &e/warpcreate create 10 m StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.delete")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate delete <player-name> &e- &3Example: &e/warpcreate delete StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.fix")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate fix <player-name> &e- &3Example: &e/warpcreate fix StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.warpqueue")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate warpqueue <page> &e- &3Example: &e/warpcreate warpqueue 4"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.approve")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate approve <player-name> &e- &3Example: &e/warpcreate approve StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.approveconfirm")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate approveconfirm <player-name> &e- &3Example: &e/warpcreate approveconfirm StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.commandAdd")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate commandAdd <command> &e- &3Example: &e/warpcreate commandAdd kit tools"));
|
||||
++count;
|
||||
}
|
||||
if (player.hasPermission("core.warpcreates.commandDel")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreate commandDel <command> &e- &3Example: &e/warpcreate commandDel kit tools"));
|
||||
++count;
|
||||
}
|
||||
helpMenu.add(Utils.replace("&e- Showing page &61 &eof &61 &e(" + count + " results)."));
|
||||
for (final String s : helpMenu) {
|
||||
Utils.sendMessage(player, s);
|
||||
}
|
||||
}
|
||||
|
||||
private void helpMenuConsole() {
|
||||
final List<String> helpMenu = new ArrayList<String>();
|
||||
int count = 0;
|
||||
helpMenu.add(Utils.replace(this.help));
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate create <time> <time-span> <player-name> &e- &3Example: &ewarpcreate create 10 m StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate delete <player-name> &e- &3Example: &ewarpcreate delete StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate fix <player-name> &e- &3Example: &ewarpcreate fix StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate warpqueue <page> &e- &3Example: &ewarpcreate warpqueue 4"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate approve <player-name> &e- &3Example: &ewarpcreate approve StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate approveconfirm <player-name> &e- &3Example: &ewarpcreate approveconfirm StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate commandAdd <command> &e- &3Example: &ewarpcreate commandAdd kit tools"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace(" &e- warpcreate commandDel <command> &e- &3Example: &ewarpcreate commandDel kit tools"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace("&e- Showing page &61 &eof &61 &e(" + count + " results)."));
|
||||
for (final String s : helpMenu) {
|
||||
Utils.sendConsoleMessage(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void helpMenu2(final CommandSender player) {
|
||||
final List<String> helpMenu = new ArrayList<String>();
|
||||
int count = 0;
|
||||
helpMenu.add(Utils.replace(this.help));
|
||||
if (player.hasPermission("core.warpcreates.giveblock")) {
|
||||
helpMenu.add(Utils.replace(" &e- /warpcreateblock giveBlock <time-span> <player-name> &e- &3Example: &e/warpcreateblock giveBlock 10 m StarZorrow"));
|
||||
++count;
|
||||
}
|
||||
helpMenu.add(Utils.replace("&e- Showing page &61 &eof &61 &e(" + count + " results)."));
|
||||
for (final String s : helpMenu) {
|
||||
Utils.sendMessage(player, s);
|
||||
}
|
||||
}
|
||||
|
||||
private void helpMenu2Console() {
|
||||
final List<String> helpMenu = new ArrayList<String>();
|
||||
int count = 0;
|
||||
helpMenu.add(Utils.replace(this.help));
|
||||
helpMenu.add(Utils.replace(" &e- warpcreateblock giveBlock <time-span> <player-name> &e- &3Example: &ewarpcreateblock giveBlock 10 m StarZorrow"));
|
||||
++count;
|
||||
helpMenu.add(Utils.replace("&e- Showing page &61 &eof &61 &e(" + count + " results)."));
|
||||
for (final String s : helpMenu) {
|
||||
Utils.sendConsoleMessage(s);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Commands.warpqueue = new ArrayList<String>();
|
||||
Commands.noPerms = "&cYou do not have permission to use this!";
|
||||
}
|
||||
}
|
783
src/str/playerwarps/commands/gui/GUI.java
Normal file
783
src/str/playerwarps/commands/gui/GUI.java
Normal file
@ -0,0 +1,783 @@
|
||||
package str.playerwarps.commands.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.google.common.collect.Multiset.Entry;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.gui.ItemBuilder;
|
||||
import str.playerwarps.gui.buttons.GUIButton;
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
import str.playerwarps.util.Utils;
|
||||
import str.playerwarps.util.Zone;
|
||||
|
||||
public class GUI implements CommandExecutor, Listener {
|
||||
|
||||
public static BukkitTask timer;
|
||||
public static HashMap<String, Boolean> check = new HashMap<String, Boolean>();
|
||||
public static ArrayList<String> order = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (cmd.getName().equalsIgnoreCase("pw")) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
Utils.sendConsoleMessage("&cYou cannot use this command in console.");
|
||||
}
|
||||
else {
|
||||
if (args.length > 0) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") == null || Bukkit.getWorld("PlayerWarps-World") == null) {
|
||||
Utils.sendMessage(sender, "&eNo &6playerwarps &efound.");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("page")) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
return false;
|
||||
}
|
||||
OfflinePlayer warpto = (OfflinePlayer) Bukkit.getOfflinePlayer(args[0]);
|
||||
if (warpto == null || !PlayerWarps.get().getCustomData().contains("Warps-Created-By." + warpto.getUniqueId().toString())) {
|
||||
Utils.sendMessage(sender, "&6" + args[0] + " &edoesn't exist!");
|
||||
Utils.sendMessage(sender, "&eUsage: &f/&eplayerwarp &e(player).");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + warpto.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + warpto.getUniqueId().toString() + ".Need-Approval") == null) {
|
||||
Utils.sendMessage(sender, "&6" + args[0] + " &edoesn't exist!");
|
||||
Utils.sendMessage(sender, "&eUsage: &f/&eplayerwarp &e(player).");
|
||||
return false;
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + warpto.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("true")) {
|
||||
if (warpto.getName() == sender.getName()) {
|
||||
Player player = (Player) sender;
|
||||
Location loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
Utils.sendMessage(sender, "&eTeleporting to &6" + sender.getName() + "'s &eplayerwarp.");
|
||||
player.teleport(loc);
|
||||
return false;
|
||||
}
|
||||
Utils.sendMessage(sender, "&cYou cannot warp to this playerwarp while it's not approved!");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
Player player = (Player) sender;
|
||||
Utils.teleportToWarp(player, warpto.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.length >= 2) {
|
||||
if (args.length > 2) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
Pattern pattern = Pattern.compile("[^0-9 ]");
|
||||
Matcher match = pattern.matcher(args[1]);
|
||||
boolean found = match.find();
|
||||
|
||||
if (found) {
|
||||
Utils.sendMessage(sender, "&cPlease enter a page number.");
|
||||
}
|
||||
else {
|
||||
int page = Integer.parseInt(args[1]);
|
||||
PaginatedGUI menu = new PaginatedGUI("PlayerWarps");
|
||||
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") == null || Bukkit.getWorld("PlayerWarps-World") == null) {
|
||||
Utils.sendMessage(sender, "&eNo &6playerwarps &efound.");
|
||||
return true;
|
||||
}
|
||||
GUIButton button4 = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).build());
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + Bukkit.getOfflinePlayer(uuid).getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString()) == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Start glass bar, own playerwarp and random playerwarp.
|
||||
|
||||
GUIButton button2 = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)7).name(" ").build());
|
||||
button2.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
for (int i = 0; i < 3; i++) {
|
||||
menu.setButton(i, button2);
|
||||
}
|
||||
|
||||
List<String> lore2 = new ArrayList<String>();
|
||||
if (Utils.getWarps() < 4) {
|
||||
lore2.add(Utils.replace("&c5 playerwarps must be approved to use this."));
|
||||
}
|
||||
else {
|
||||
lore2.add("");
|
||||
lore2.add(Utils.replace("&7Players&7: &3&k12345"));
|
||||
lore2.add("");
|
||||
lore2.add(Utils.replace("&a[Click to teleport]"));
|
||||
}
|
||||
// if (Utils.getWarps() >= 1) {
|
||||
GUIButton button3 = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).lore(lore2).build());
|
||||
button3.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
if (Utils.getWarps() > 4) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ArrayList<String> random = new ArrayList<>();
|
||||
for (String r : set) {
|
||||
random.add(r);
|
||||
}
|
||||
String uuidd = random.get(getRandomInt(0, random.size()));
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuidd.toString() + ".worldname") != null) {
|
||||
UUID uuid1 = uuid.fromString(uuidd);
|
||||
if (Bukkit.getPlayer(uuid1) != null) {
|
||||
Player warpto2 = (Player) Bukkit.getPlayer(uuid1);
|
||||
Utils.teleportToWarp(player, warpto2.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
else {
|
||||
OfflinePlayer warpto2 = (OfflinePlayer) Bukkit.getOfflinePlayer(uuid1);
|
||||
Utils.teleportToWarp(player, warpto2.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SkullMeta sm2 = (SkullMeta) button3.getItem().getItemMeta();
|
||||
sm2.setDisplayName(Utils.replace1("&6&lRandom Warp"));
|
||||
button3.getItem().setItemMeta(sm2);
|
||||
menu.setButton(3, button3);
|
||||
|
||||
menu.setButton(4, button2);
|
||||
|
||||
List<String> ownWarpLore = new ArrayList<String>();
|
||||
Player player1 = (Player) sender;
|
||||
if (player1 == null || !PlayerWarps.get().getCustomData().contains("Warps-Created-By." + player1.getUniqueId().toString())) {
|
||||
ownWarpLore.add("&7You do not own a Player Warp");
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player1.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player1.getUniqueId().toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player1.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("false")) {
|
||||
ownWarpLore.add("&aYour warp is approved!");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(player1.getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
ownWarpLore.add(Utils.replace("&7Players&7: &3" + sort));
|
||||
ownWarpLore.add("");
|
||||
}
|
||||
else {
|
||||
ownWarpLore.add("&cYour warp is not approved!");
|
||||
ownWarpLore.add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
ownWarpLore.add("&a[Click to teleport]");
|
||||
}
|
||||
GUIButton ownWarp = new GUIButton(ItemBuilder.start(Material.BED).name(PaginatedGUI.OWN_WARP).lore(ownWarpLore).build());
|
||||
ownWarp.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player == null || !PlayerWarps.get().getCustomData().contains("Warps-Created-By." + player.getUniqueId().toString())) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Need-Approval") != null) {
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
Location loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
Utils.sendMessage(player, "&eTeleporting to &6" + player.getName() + "'s &eplayerwarp.");
|
||||
player.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
menu.setButton(5, ownWarp);
|
||||
|
||||
for (int i = 6; i < 9; i++) {
|
||||
menu.setButton(i, button2);
|
||||
}
|
||||
|
||||
// End of glass bar, own playerwarp and random playerwarp.
|
||||
|
||||
if (Utils.getWarps() >= 1) {
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
lore.add(Utils.replace("&7Players&7: &3" + sort));
|
||||
lore.add("");
|
||||
lore.add(Utils.replace("&a[Click to teleport]"));
|
||||
GUIButton button = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).name(Bukkit.getPlayer(uuid).getName()).lore(lore).build());
|
||||
String warp = button.getItem().getItemMeta().getDisplayName().replace(Utils.replace1("&6&l"), "");
|
||||
Player warpto = (Player) Bukkit.getPlayer(warp);
|
||||
button.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
Utils.teleportToWarp(player, warpto.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eYou cannot warp to &6" + warpto.getName() + "'s &eplayerwarp while they are building.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SkullMeta sm1 = (SkullMeta) button.getItem().getItemMeta();
|
||||
sm1.setOwner(Bukkit.getPlayer(button.getItem().getItemMeta().getDisplayName()).getName());
|
||||
sm1.setDisplayName(Utils.replace1("&6&l" + Bukkit.getPlayer(uuid).getName()));
|
||||
button.getItem().setItemMeta(sm1);
|
||||
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
for (int i = 0; i < PlayerWarps.get().warpsort.size(); i++) {
|
||||
String s1 = PlayerWarps.get().warpsort.get(i);
|
||||
String s2 = s1.substring(s1.indexOf("-") + 2);
|
||||
int sort1 = PlayerWarps.get().warpsort.lastIndexOf(s1) + 9;
|
||||
if (s2.trim().equals(uuid.toString())) {
|
||||
menu.setButton(sort1, button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
lore.add(Utils.replace1("&7Players&7: &3" + sort));
|
||||
lore.add("");
|
||||
lore.add(Utils.replace1("&a[Click to teleport]"));
|
||||
if (!Bukkit.getOfflinePlayer(uuid).hasPlayedBefore() || Bukkit.getOfflinePlayer(uuid) == null) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
GUIButton button = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).name(Bukkit.getOfflinePlayer(uuid).getName()).lore(lore).build());
|
||||
String warp = button.getItem().getItemMeta().getDisplayName().replace(Utils.replace1("&6&l"), "");
|
||||
OfflinePlayer warpto = (OfflinePlayer) Bukkit.getOfflinePlayer(warp);
|
||||
|
||||
|
||||
button.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
Utils.teleportToWarp(player, warpto.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eYou cannot warp to &6" + warpto.getName() + "'s &eplayerwarp while they are building.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SkullMeta sm1 = (SkullMeta) button.getItem().getItemMeta();
|
||||
sm1.setOwner(Bukkit.getOfflinePlayer(button.getItem().getItemMeta().getDisplayName()).getName());
|
||||
sm1.setDisplayName(Utils.replace1("&6&l" + Bukkit.getOfflinePlayer(uuid).getName()));
|
||||
button.getItem().setItemMeta(sm1);
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
for (int i = 0; i < PlayerWarps.get().warpsort.size(); i++) {
|
||||
String s1 = PlayerWarps.get().warpsort.get(i);
|
||||
String s2 = s1.substring(s1.indexOf("-") + 2);
|
||||
int sort1 = PlayerWarps.get().warpsort.lastIndexOf(s1) + 9;
|
||||
if (s2.trim().equals(uuid.toString())) {
|
||||
menu.setButton(sort1, button);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// Utils.sendMessage(sender, "&eNo approved &6playerwarps &efound.");
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (Utils.getWarps() == 0) {
|
||||
// Utils.sendMessage(sender, "&eNo approved &6playerwarps &efound.");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
Player player1 = (Player) sender;
|
||||
if (((menu.getMaxPage() + 1) < page) || page == 0) {
|
||||
Utils.sendMessage(player1, "&cInvalid Page number. Pages: " + (menu.getCurrentPage() + 1) + " - " + (menu.getFinalPage() + 1));
|
||||
return false;
|
||||
}
|
||||
menu.setCurrentPage(page - 1);
|
||||
menu.setDisplayName("Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)" );
|
||||
player1.openInventory(menu.getInventory());
|
||||
menu.getInventory().setMaxStackSize(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.length == 0) {
|
||||
PaginatedGUI menu = new PaginatedGUI("PlayerWarps");
|
||||
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") == null || Bukkit.getWorld("PlayerWarps-World") == null) {
|
||||
Utils.sendMessage(sender, "&eNo &6playerwarps &efound.");
|
||||
return true;
|
||||
}
|
||||
GUIButton button4 = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).build());
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + Bukkit.getOfflinePlayer(uuid).getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString()) == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Start glass bar, own playerwarp and random playerwarp.
|
||||
|
||||
GUIButton button2 = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)7).name(" ").build());
|
||||
button2.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
for (int i = 0; i < 3; i++) {
|
||||
menu.setButton(i, button2);
|
||||
}
|
||||
|
||||
List<String> lore2 = new ArrayList<String>();
|
||||
if (Utils.getWarps() < 4) {
|
||||
lore2.add(Utils.replace("&c5 playerwarps must be approved to use this."));
|
||||
}
|
||||
else {
|
||||
lore2.add("");
|
||||
lore2.add(Utils.replace("&7Players&7: &3&k12345"));
|
||||
lore2.add("");
|
||||
lore2.add(Utils.replace("&a[Click to teleport]"));
|
||||
}
|
||||
// if (Utils.getWarps() >= 1) {
|
||||
GUIButton button3 = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).lore(lore2).build());
|
||||
button3.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
if (Utils.getWarps() > 4) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ArrayList<String> random = new ArrayList<>();
|
||||
for (String r : set) {
|
||||
random.add(r);
|
||||
}
|
||||
String uuidd = random.get(getRandomInt(0, random.size()));
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuidd.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuidd.toString() + ".worldname") != null) {
|
||||
UUID uuid1 = uuid.fromString(uuidd);
|
||||
if (Bukkit.getPlayer(uuid1) != null) {
|
||||
Player warpto2 = (Player) Bukkit.getPlayer(uuid1);
|
||||
Utils.teleportToWarp(player, warpto2.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
else {
|
||||
OfflinePlayer warpto2 = (OfflinePlayer) Bukkit.getOfflinePlayer(uuid1);
|
||||
Utils.teleportToWarp(player, warpto2.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SkullMeta sm2 = (SkullMeta) button3.getItem().getItemMeta();
|
||||
sm2.setDisplayName(Utils.replace1("&6&lRandom Warp"));
|
||||
button3.getItem().setItemMeta(sm2);
|
||||
menu.setButton(3, button3);
|
||||
|
||||
menu.setButton(4, button2);
|
||||
|
||||
List<String> ownWarpLore = new ArrayList<String>();
|
||||
Player player1 = (Player) sender;
|
||||
if (player1 == null || !PlayerWarps.get().getCustomData().contains("Warps-Created-By." + player1.getUniqueId().toString())) {
|
||||
ownWarpLore.add("&7You do not own a Player Warp");
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player1.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player1.getUniqueId().toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player1.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("false")) {
|
||||
ownWarpLore.add("&aYour warp is approved!");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(player1.getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
ownWarpLore.add(Utils.replace("&7Players&7: &3" + sort));
|
||||
ownWarpLore.add("");
|
||||
}
|
||||
else {
|
||||
ownWarpLore.add("&cYour warp is not approved!");
|
||||
ownWarpLore.add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
ownWarpLore.add("&a[Click to teleport]");
|
||||
}
|
||||
GUIButton ownWarp = new GUIButton(ItemBuilder.start(Material.BED).name(PaginatedGUI.OWN_WARP).lore(ownWarpLore).build());
|
||||
ownWarp.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player == null || !PlayerWarps.get().getCustomData().contains("Warps-Created-By." + player.getUniqueId().toString())) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Need-Approval") != null) {
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
Location loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
Utils.sendMessage(player, "&eTeleporting to &6" + player.getName() + "'s &eplayerwarp.");
|
||||
player.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
menu.setButton(5, ownWarp);
|
||||
|
||||
for (int i = 6; i < 9; i++) {
|
||||
menu.setButton(i, button2);
|
||||
}
|
||||
// }
|
||||
|
||||
// End of glass bar, own playerwarp and random playerwarp.
|
||||
|
||||
if (Utils.getWarps() >= 1) {
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
lore.add(Utils.replace("&7Players&7: &3" + sort));
|
||||
lore.add("");
|
||||
lore.add(Utils.replace("&a[Click to teleport]"));
|
||||
GUIButton button = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).name(Bukkit.getPlayer(uuid).getName()).lore(lore).build());
|
||||
String warp = button.getItem().getItemMeta().getDisplayName().replace(Utils.replace1("&6&l"), "");
|
||||
Player warpto = (Player) Bukkit.getPlayer(warp);
|
||||
button.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
Utils.teleportToWarp(player, warpto.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eYou cannot warp to &6" + warpto.getName() + "'s &eplayerwarp while they are building.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SkullMeta sm1 = (SkullMeta) button.getItem().getItemMeta();
|
||||
sm1.setOwner(Bukkit.getPlayer(button.getItem().getItemMeta().getDisplayName()).getName());
|
||||
sm1.setDisplayName(Utils.replace1("&6&l" + Bukkit.getPlayer(uuid).getName()));
|
||||
button.getItem().setItemMeta(sm1);
|
||||
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
for (int i = 0; i < PlayerWarps.get().warpsort.size(); i++) {
|
||||
String s1 = PlayerWarps.get().warpsort.get(i);
|
||||
String s2 = s1.substring(s1.indexOf("-") + 2);
|
||||
int sort1 = PlayerWarps.get().warpsort.lastIndexOf(s1) + 9;
|
||||
if (s2.trim().equals(uuid.toString())) {
|
||||
menu.setButton(sort1, button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("");
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
lore.add(Utils.replace1("&7Players&7: &3" + sort));
|
||||
lore.add("");
|
||||
lore.add(Utils.replace1("&a[Click to teleport]"));
|
||||
if (!Bukkit.getOfflinePlayer(uuid).hasPlayedBefore() || Bukkit.getOfflinePlayer(uuid) == null) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
GUIButton button = new GUIButton(ItemBuilder.start(Material.SKULL_ITEM).data((short)3).name(Bukkit.getOfflinePlayer(uuid).getName()).lore(lore).build());
|
||||
String warp = button.getItem().getItemMeta().getDisplayName().replace(Utils.replace1("&6&l"), "");
|
||||
OfflinePlayer warpto = (OfflinePlayer) Bukkit.getOfflinePlayer(warp);
|
||||
|
||||
|
||||
button.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() < event.getInventory().getSize()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
Utils.teleportToWarp(player, warpto.getUniqueId().toString());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eYou cannot warp to &6" + warpto.getName() + "'s &eplayerwarp while they are building.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SkullMeta sm1 = (SkullMeta) button.getItem().getItemMeta();
|
||||
sm1.setOwner(Bukkit.getOfflinePlayer(button.getItem().getItemMeta().getDisplayName()).getName());
|
||||
sm1.setDisplayName(Utils.replace1("&6&l" + Bukkit.getOfflinePlayer(uuid).getName()));
|
||||
button.getItem().setItemMeta(sm1);
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
for (int i = 0; i < PlayerWarps.get().warpsort.size(); i++) {
|
||||
String s1 = PlayerWarps.get().warpsort.get(i);
|
||||
String s2 = s1.substring(s1.indexOf("-") + 2);
|
||||
int sort1 = PlayerWarps.get().warpsort.lastIndexOf(s1) + 9;
|
||||
if (s2.trim().equals(uuid.toString())) {
|
||||
menu.setButton(sort1, button);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// Utils.sendMessage(sender, "&eNo approved &6playerwarps &efound.");
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (Utils.getWarps() == 0) {
|
||||
// Utils.sendMessage(sender, "&eNo approved &6playerwarps &efound.");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
Player player1 = (Player) sender;
|
||||
menu.setDisplayName("Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)" );
|
||||
player1.openInventory(menu.getInventory());
|
||||
menu.getInventory().setMaxStackSize(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int getRandomInt(int min, int max) {
|
||||
Random random = new Random();
|
||||
int theMin = min;
|
||||
int theMax = max;
|
||||
int result = random.nextInt(theMax - theMin) + theMin;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void sortWarps() {
|
||||
if (PlayerWarps.get().getCustomData().getStringList("Warps-Created-By") == null) {
|
||||
return;
|
||||
}
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
int sort = Bukkit.getWorld("PlayerWarp " + uuid.toString()).getPlayers().size();
|
||||
PlayerWarps.get().warpsort.add(sort + " - " + uuid.toString());
|
||||
}
|
||||
Collections.sort(PlayerWarps.get().warpsort, Collections.reverseOrder());
|
||||
if (PlayerWarps.get().getCustomData().getStringList("WarpList") == null) {
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", PlayerWarps.get().warpsort);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else {
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", null);
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", PlayerWarps.get().warpsort);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
172
src/str/playerwarps/gui/ItemBuilder.java
Normal file
172
src/str/playerwarps/gui/ItemBuilder.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* ItemBuilder.java
|
||||
* Copyright (c) 2017 Sam Jakob Harker
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package str.playerwarps.gui;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
private ItemStack stack;
|
||||
|
||||
/**
|
||||
* Create/Modify custom {@link ItemStack}s easily.
|
||||
* If you want to create rather than modify an ItemStack,
|
||||
* use {@link ItemBuilder#start(Material)} instead.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* It supports shorthand for setting the following attributes:
|
||||
* <ul>
|
||||
* <li>Name</li>
|
||||
* <li>Amount</li>
|
||||
* <li>Lore</li>
|
||||
* <li>Data / Durability</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param stack The ItemStack you want to modify.
|
||||
*/
|
||||
public ItemBuilder(ItemStack stack){
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a custom {@link ItemStack} easily.
|
||||
*
|
||||
* @param material The {@link Material} of the ItemStack that you want to create.
|
||||
* @return A new {@link ItemBuilder} object.
|
||||
*/
|
||||
public static ItemBuilder start(Material material){
|
||||
return new ItemBuilder(new ItemStack(material));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name of the item.
|
||||
* Color Codes are supported (and should be prepended with an ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the ItemStack.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder name(String name){
|
||||
ItemMeta stackMeta = stack.getItemMeta();
|
||||
stackMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
stack.setItemMeta(stackMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of the item.
|
||||
*
|
||||
* @param amount The desired amount of the ItemStack.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder amount(int amount){
|
||||
stack.setAmount(amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lore of the item. (Shorthand - unlimited argument version)
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an ampersand [&]; e.g. &c for red.)
|
||||
* <b>Note:</b> Each argument will be a line of the lore.
|
||||
*
|
||||
* @param lore The desired lore of the item.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder lore(String... lore){
|
||||
for(int i = 0; i < lore.length; i++){
|
||||
lore[i] = ChatColor.translateAlternateColorCodes('&', lore[i]);
|
||||
}
|
||||
|
||||
ItemMeta stackMeta = stack.getItemMeta();
|
||||
stackMeta.setLore(Arrays.asList(lore));
|
||||
stack.setItemMeta(stackMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lore of the item. (Reference - {@link List<String>} version)
|
||||
* This essentially just wrapper for {@link ItemMeta#setLore(List)}, however, with color replacement.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param lore The desired lore of the item.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder lore(List<String> lore){
|
||||
for(int i = 0; i < lore.size(); i++){
|
||||
lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i)));
|
||||
}
|
||||
|
||||
ItemMeta stackMeta = stack.getItemMeta();
|
||||
stackMeta.setLore(lore);
|
||||
stack.setItemMeta(stackMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias for {@link ItemBuilder#durability(short)}.
|
||||
* Intended to improve readability of code.
|
||||
*
|
||||
* @param data The desired data value (durability) of the item.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder data(short data){
|
||||
stack.setDurability(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the durability of the item.
|
||||
*
|
||||
* @param durability The desired durability of the item.
|
||||
* @return The updated {@link ItemBuilder} object.
|
||||
*/
|
||||
public ItemBuilder durability(short durability){
|
||||
stack.setDurability(durability);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class' internally modified {@link ItemStack} object.
|
||||
*
|
||||
* @return The updated ItemStack.
|
||||
*/
|
||||
public ItemStack build(){
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
15
src/str/playerwarps/gui/buttons/ButtonListener.java
Normal file
15
src/str/playerwarps/gui/buttons/ButtonListener.java
Normal file
@ -0,0 +1,15 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public interface ButtonListener {
|
||||
|
||||
/**
|
||||
* The {@link InventoryClickEvent} that should be called and
|
||||
* executed when the associated {@link GUIButton} is clicked.
|
||||
*
|
||||
* @param event The event that should be called and executed.
|
||||
*/
|
||||
void onClick(InventoryClickEvent event);
|
||||
|
||||
}
|
48
src/str/playerwarps/gui/buttons/GUIButton.java
Normal file
48
src/str/playerwarps/gui/buttons/GUIButton.java
Normal file
@ -0,0 +1,48 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class GUIButton {
|
||||
|
||||
private ButtonListener listener;
|
||||
private ItemStack item;
|
||||
|
||||
/**
|
||||
* Creates a GUIButton with the {@link ItemStack} as it's 'icon' in the inventory.
|
||||
*
|
||||
* @param item The desired 'icon' for the GUIButton.
|
||||
*/
|
||||
public GUIButton(ItemStack item){
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
*
|
||||
* @param listener The listener to be executed on button click.
|
||||
*/
|
||||
public void setListener(ButtonListener listener){
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
* This is mostly for internal use by the API and is likely not useful to you.
|
||||
*
|
||||
* @return The listener to be executed on button click.
|
||||
*/
|
||||
public ButtonListener getListener(){
|
||||
return listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ItemStack} that will be used as the GUIButton's 'icon' in an inventory.
|
||||
*
|
||||
* @return The GUIButton's 'icon'.
|
||||
*/
|
||||
public ItemStack getItem(){
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
}
|
15
src/str/playerwarps/gui/buttons/InventoryCloseListener.java
Normal file
15
src/str/playerwarps/gui/buttons/InventoryCloseListener.java
Normal file
@ -0,0 +1,15 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public interface InventoryCloseListener {
|
||||
|
||||
/**
|
||||
* The {@link InventoryCloseEvent} that should be called and
|
||||
* executed when the associated {@link PaginatedGUI} is closed.
|
||||
*
|
||||
* @param event The event that should be called and executed.
|
||||
*/
|
||||
void onClose(InventoryCloseEvent event);
|
||||
|
||||
}
|
32
src/str/playerwarps/gui/buttons/InventoryListenerGUI.java
Normal file
32
src/str/playerwarps/gui/buttons/InventoryListenerGUI.java
Normal file
@ -0,0 +1,32 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
|
||||
public class InventoryListenerGUI implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
// Determine if the Inventory was a PaginatedGUI
|
||||
if (event.getInventory().getHolder() != null
|
||||
&& event.getInventory().getHolder() instanceof PaginatedGUI) {
|
||||
|
||||
// Get the instance of the PaginatedGUI that was clicked.
|
||||
PaginatedGUI paginatedGUI = (PaginatedGUI) event.getInventory().getHolder();
|
||||
|
||||
// Then, assume the slot holds a GUIButton and attempt to get the button.
|
||||
GUIButton button = paginatedGUI.getButton(event.getSlot());
|
||||
|
||||
// Finally, if the slot did actually hold a GUIButton (that has a listener)...
|
||||
if (button != null && button.getListener() != null) {
|
||||
// ...execute that button's listener.
|
||||
button.getListener().onClick(event);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
import str.playerwarps.gui.types.PaginatedGUIAllPages;
|
||||
import str.playerwarps.gui.types.PaginatedGUICP;
|
||||
|
||||
public class InventoryListenerGUIAllPages implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
// Determine if the Inventory was a PaginatedGUI
|
||||
if (event.getInventory().getHolder() != null
|
||||
&& event.getInventory().getHolder() instanceof PaginatedGUIAllPages) {
|
||||
|
||||
// Get the instance of the PaginatedGUI that was clicked.
|
||||
PaginatedGUIAllPages paginatedGUI = (PaginatedGUIAllPages) event.getInventory().getHolder();
|
||||
|
||||
// Then, assume the slot holds a GUIButton and attempt to get the button.
|
||||
GUIButton button = paginatedGUI.getButton(event.getSlot());
|
||||
|
||||
// Finally, if the slot did actually hold a GUIButton (that has a listener)...
|
||||
if (button != null && button.getListener() != null) {
|
||||
// ...execute that button's listener.
|
||||
button.getListener().onClick(event);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
// Determine if the Inventory was a PaginatedGUI.
|
||||
if (event.getInventory().getHolder() != null
|
||||
&& event.getInventory().getHolder() instanceof PaginatedGUIAllPages) {
|
||||
|
||||
// Set the instance of the Player who closed the PaginatedGUI.
|
||||
Player player = (Player) event.getPlayer();
|
||||
|
||||
// Get the instance of the PaginatedGUI that was closed.
|
||||
PaginatedGUIAllPages inventory = (PaginatedGUIAllPages) event.getInventory().getHolder();
|
||||
|
||||
// Then, assume the inventory did actually have a listener.
|
||||
if (inventory != null && inventory.getCloseListener() != null) {
|
||||
// Finally, if the PaginatedGUI was a sub-menu...
|
||||
if (PaginatedGUI.inSubMenu.get(player) == true) {
|
||||
// ...execute that inventory's listener.
|
||||
inventory.getCloseListener().onClose(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
src/str/playerwarps/gui/buttons/InventoryListenerGUICP.java
Normal file
59
src/str/playerwarps/gui/buttons/InventoryListenerGUICP.java
Normal file
@ -0,0 +1,59 @@
|
||||
package str.playerwarps.gui.buttons;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
import str.playerwarps.gui.types.PaginatedGUIAllPages;
|
||||
import str.playerwarps.gui.types.PaginatedGUICP;
|
||||
|
||||
public class InventoryListenerGUICP implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
// Determine if the Inventory was a PaginatedGUI
|
||||
if (event.getInventory().getHolder() != null
|
||||
&& event.getInventory().getHolder() instanceof PaginatedGUICP) {
|
||||
|
||||
// Get the instance of the PaginatedGUI that was clicked.
|
||||
PaginatedGUICP paginatedGUI = (PaginatedGUICP) event.getInventory().getHolder();
|
||||
|
||||
// Then, assume the slot holds a GUIButton and attempt to get the button.
|
||||
GUIButton button = paginatedGUI.getButton(event.getSlot());
|
||||
|
||||
// Finally, if the slot did actually hold a GUIButton (that has a listener)...
|
||||
if (button != null && button.getListener() != null) {
|
||||
// ...execute that button's listener.
|
||||
button.getListener().onClick(event);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
// Determine if the Inventory was a PaginatedGUI.
|
||||
if (event.getInventory().getHolder() != null
|
||||
&& event.getInventory().getHolder() instanceof PaginatedGUICP) {
|
||||
|
||||
// Set the instance of the Player who closed the PaginatedGUI.
|
||||
Player player = (Player) event.getPlayer();
|
||||
|
||||
// Get the instance of the PaginatedGUI that was closed.
|
||||
PaginatedGUICP inventory = (PaginatedGUICP) event.getInventory().getHolder();
|
||||
|
||||
// Then, assume the inventory did actually have a listener.
|
||||
if (inventory != null && inventory.getCloseListener() != null) {
|
||||
// Finally, if the PaginatedGUI was a sub-menu...
|
||||
if (PaginatedGUICP.inSubMenu.get(player) == true) {
|
||||
// ...execute that inventory's listener.
|
||||
inventory.getCloseListener().onClose(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
617
src/str/playerwarps/gui/types/PaginatedGUI.java
Normal file
617
src/str/playerwarps/gui/types/PaginatedGUI.java
Normal file
@ -0,0 +1,617 @@
|
||||
/*
|
||||
* PaginatedGUI.java
|
||||
* Copyright (c) 2017 Sam Jakob Harker
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package str.playerwarps.gui.types;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.commands.gui.GUI;
|
||||
import str.playerwarps.gui.ItemBuilder;
|
||||
import str.playerwarps.gui.buttons.GUIButton;
|
||||
import str.playerwarps.gui.buttons.InventoryListenerGUI;
|
||||
import str.playerwarps.util.TitleUpdater_1_8_R3;
|
||||
import str.playerwarps.util.Utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PaginatedGUI implements InventoryHolder {
|
||||
|
||||
/* BEGIN: CONFIGURATION */
|
||||
private static final String CHAT_PREFIX = "&6";
|
||||
private static final String NO_PREVIOUS_PAGES = "&cThere are no previous pages.";
|
||||
private static final String NO_ADDITIONAL_PAGES = "&cThere are no additional pages.";
|
||||
|
||||
private static final String PREVIOUS_PAGE = "&cPrevious Page &7(&6{previousPage}&7/&6{maxPages}&7)";
|
||||
private static final String CURRENT_PAGE = "&aPage &7(&6{currentPage}&7/&6{maxPages}&7)";
|
||||
private static final String NEXT_PAGE = "&aNext Page &7(&6{nextPage}&7/&6{maxPages}&7)";
|
||||
public static final String OWN_WARP = "&a&lYour Player Warp";
|
||||
/* END: CONFIGURATION */
|
||||
|
||||
private static InventoryListenerGUI inventoryListenerGUI;
|
||||
public static HashMap<Player, Boolean> inSubMenu = new HashMap<Player, Boolean>();
|
||||
private Map<Integer, GUIButton> items;
|
||||
private Map<Integer, GUIButton> toolbarItems;
|
||||
private Map<Integer, GUIButton> glassBarItems;
|
||||
private int currentPage;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates a PaginatedGUI. This is a Spigot 'Inventory Menu' that
|
||||
* will automatically add pages to accommodate additional items.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public PaginatedGUI(String name){
|
||||
items = new HashMap<>();
|
||||
toolbarItems = new HashMap<>();
|
||||
glassBarItems = new HashMap<>();
|
||||
currentPage = 0;
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public void setDisplayName(String name){
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> If your inventory's display name contains
|
||||
* color codes, this will have substituted the
|
||||
* ampersands (&)s with the rendering engine's
|
||||
* symbol (§).
|
||||
*
|
||||
* @return The inventory's display name.
|
||||
*/
|
||||
public String getDisplayName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} to the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> This will place the button after the highest slot.
|
||||
* So if you have buttons in slot 0, 1 and 5, this will place the
|
||||
* added button in slot 6.
|
||||
*
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void addButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : items.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
if (items.keySet().size() == 0) {
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
else {
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
}
|
||||
|
||||
public void addBarButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : glassBarItems.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
glassBarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void setButton(int slot, GUIButton button){
|
||||
items.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
*/
|
||||
public void removeButton(int slot){
|
||||
items.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link GUIButton} in the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the GUIButton that you wish to get.
|
||||
* @return The GUIButton in the provided slot.
|
||||
*/
|
||||
public GUIButton getButton(int slot) {
|
||||
if (slot < 36) {
|
||||
if (currentPage > 0) {
|
||||
return items.get(slot + (36 * currentPage));
|
||||
}
|
||||
return items.get(slot);
|
||||
}
|
||||
else {
|
||||
return toolbarItems.get(slot - 36);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI's toolbar.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void setToolbarItem(int slot, GUIButton button) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void removeToolbarItem(int slot) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the max page is currently open as it cannot go further.)
|
||||
*/
|
||||
public boolean nextPage(){
|
||||
if(currentPage < getFinalPage()){
|
||||
currentPage++;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Decrements the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the first page is currently active as it cannot go further.)
|
||||
*/
|
||||
|
||||
public boolean previousPage(){
|
||||
if(currentPage > 0) {
|
||||
currentPage--;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias for {@link #getFinalPage()}.
|
||||
*
|
||||
* @deprecated Use {@link #getFinalPage()} instead.
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getMaxPage(){
|
||||
return getFinalPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the final page of the PaginatedGUI.
|
||||
*
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getFinalPage(){
|
||||
// Get the highest slot number.
|
||||
int slot = 0;
|
||||
for(int nextSlot : items.keySet()){
|
||||
if(nextSlot > slot){
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to make the math easier.
|
||||
double highestSlot = slot + 1;
|
||||
|
||||
// Divide by 45 and round up to get the page number.
|
||||
// Then subtract one to convert it to an index.
|
||||
return (int) Math.ceil(highestSlot / (double) 36) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the current page of the PaginatedGUI.
|
||||
*
|
||||
* @return The current page number.
|
||||
*/
|
||||
public int getCurrentPage(){
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of the current page of the PaginatedGUI.
|
||||
*
|
||||
* @return Sets the current page number to what you wish.
|
||||
*/
|
||||
public void setCurrentPage(int page){
|
||||
currentPage = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias that executes {@link HumanEntity#closeInventory()} and then
|
||||
* {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* @param holder The HumanEntity that you wish to refresh the inventory for.
|
||||
*/
|
||||
public void refreshInventory(HumanEntity holder) {
|
||||
Inventory items = getInventory();
|
||||
holder.getOpenInventory().getTopInventory().setContents(items.getContents());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Spigot {@link Inventory} that represents the PaginatedGUI.
|
||||
* This can then by shown to a player using {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* This also allows getting the PaginatedGUI instance with {@link InventoryHolder#getInventory()}.
|
||||
* Used internally ({@link InventoryListenerGUI}) to get the GUIButton and therefore listener from the raw slot.
|
||||
*
|
||||
* @return The Spigot Inventory that represents the PaginatedGUI.
|
||||
*/
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
// Create an inventory (and set an appropriate size.)
|
||||
// TODO: Allow customisation of inventory size. Maybe at first, only if the inventory is not paginated.
|
||||
Inventory inventory = Bukkit.createInventory(this, (getFinalPage() > 0) ? 45 : 36, name);
|
||||
|
||||
/* BEGIN PAGINATION */
|
||||
GUIButton backButton = new GUIButton(ItemBuilder.start(Material.MELON).name(PREVIOUS_PAGE
|
||||
.replaceAll(Pattern.quote("{previousPage}"), String.valueOf((currentPage + 1) - 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage() + 1))
|
||||
)
|
||||
.build());
|
||||
GUIButton nextButton = new GUIButton(ItemBuilder.start(Material.SPECKLED_MELON).name(NEXT_PAGE
|
||||
.replaceAll(Pattern.quote("{nextPage}"), String.valueOf((currentPage + 1) + 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage() + 1))
|
||||
)
|
||||
.build());
|
||||
GUIButton glassPane = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)7).name(" ").build());
|
||||
glassPane.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
if (getFinalPage() > 0) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eRight click to view all pages"));
|
||||
|
||||
ItemMeta stackMeta1 = backButton.getItem().getItemMeta();
|
||||
stackMeta1.setLore(lore);
|
||||
backButton.getItem().setItemMeta(stackMeta1);
|
||||
|
||||
ItemMeta stackMeta2 = nextButton.getItem().getItemMeta();
|
||||
stackMeta2.setLore(lore);
|
||||
nextButton.getItem().setItemMeta(stackMeta2);
|
||||
}
|
||||
backButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUI menu = (PaginatedGUI) event.getClickedInventory().getHolder();
|
||||
if (event.isLeftClick()) {
|
||||
if(!menu.previousPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_PREVIOUS_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
TitleUpdater_1_8_R3.update(player, ChatColor.translateAlternateColorCodes('&', "Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)"));
|
||||
}
|
||||
else if (event.isRightClick()) {
|
||||
PaginatedGUIAllPages menu2 = new PaginatedGUIAllPages("Open a page...");
|
||||
menu2.setCloseListener(event2 -> {
|
||||
Bukkit.getScheduler().runTaskLater(PlayerWarps.get(), new Runnable() {
|
||||
public void run() {
|
||||
Player player = (Player) event2.getPlayer();
|
||||
if (inSubMenu.get(player) == true) {
|
||||
inSubMenu.remove(player);
|
||||
Utils.performCommand(player, "playerwarps page " + (currentPage + 1));
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
});
|
||||
for (int i = 0; i < (getFinalPage() + 1); i++) {
|
||||
if (currentPage == i) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to open"));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&aCurrent page"));
|
||||
GUIButton book = new GUIButton(ItemBuilder.start(Material.ENCHANTED_BOOK).amount(i + 1).lore(lore).name("&ePage " + (i + 1)).build());
|
||||
final int o = i;
|
||||
book.setListener(event1 -> {
|
||||
event1.setCancelled(true);
|
||||
Player player = (Player) event1.getWhoClicked();
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.put(player, false);
|
||||
}
|
||||
Utils.performCommand(player, "playerwarp page " + (o + 1));
|
||||
});
|
||||
menu2.addButton(book);
|
||||
}
|
||||
else {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to open"));
|
||||
GUIButton book = new GUIButton(ItemBuilder.start(Material.BOOK).amount(i + 1).lore(lore).name("&ePage " + (i + 1)).build());
|
||||
final int o = i;
|
||||
book.setListener(event1 -> {
|
||||
event1.setCancelled(true);
|
||||
Player player = (Player) event1.getWhoClicked();
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.put(player, false);
|
||||
}
|
||||
Utils.performCommand(player, "playerwarp page " + (o + 1));
|
||||
});
|
||||
menu2.addButton(book);
|
||||
}
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (event.getWhoClicked().getOpenInventory() != null) event.getWhoClicked().closeInventory();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.remove(player);
|
||||
inSubMenu.put(player, true);
|
||||
}
|
||||
else {
|
||||
inSubMenu.put(player, true);
|
||||
}
|
||||
event.getWhoClicked().openInventory(menu2.getInventory());
|
||||
}
|
||||
});
|
||||
|
||||
nextButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUI menu = (PaginatedGUI) event.getClickedInventory().getHolder();
|
||||
if (event.isLeftClick()) {
|
||||
if(!menu.nextPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_ADDITIONAL_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
TitleUpdater_1_8_R3.update(player, ChatColor.translateAlternateColorCodes('&', "Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)"));
|
||||
}
|
||||
if (event.isRightClick()) {
|
||||
PaginatedGUIAllPages menu2 = new PaginatedGUIAllPages("Open a page...");
|
||||
menu2.setCloseListener(event2 -> {
|
||||
Bukkit.getScheduler().runTaskLater(PlayerWarps.get(), new Runnable() {
|
||||
public void run() {
|
||||
Player player = (Player) event2.getPlayer();
|
||||
if (inSubMenu.get(player) == true) {
|
||||
inSubMenu.remove(player);
|
||||
Utils.performCommand(player, "playerwarps page " + (currentPage + 1));
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
});
|
||||
for (int i = 0; i < (getFinalPage() + 1); i++) {
|
||||
if (currentPage == i) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to open"));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&aCurrent page"));
|
||||
GUIButton book = new GUIButton(ItemBuilder.start(Material.ENCHANTED_BOOK).amount(i + 1).lore(lore).name("&ePage " + (i + 1)).build());
|
||||
final int o = i;
|
||||
book.setListener(event1 -> {
|
||||
event1.setCancelled(true);
|
||||
Player player = (Player) event1.getWhoClicked();
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.put(player, false);
|
||||
}
|
||||
Utils.performCommand(player, "playerwarp page " + (o + 1));
|
||||
});
|
||||
menu2.addButton(book);
|
||||
}
|
||||
else {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to open"));
|
||||
GUIButton book = new GUIButton(ItemBuilder.start(Material.BOOK).amount(i + 1).lore(lore).name("&ePage " + (i + 1)).build());
|
||||
final int o = i;
|
||||
book.setListener(event1 -> {
|
||||
event1.setCancelled(true);
|
||||
Player player = (Player) event1.getWhoClicked();
|
||||
if (player.getOpenInventory() != null) player.closeInventory();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.put(player, false);
|
||||
}
|
||||
Utils.performCommand(player, "playerwarp page " + (o + 1));
|
||||
});
|
||||
menu2.addButton(book);
|
||||
}
|
||||
}
|
||||
if (event.getWhoClicked().getOpenInventory() != null) event.getWhoClicked().closeInventory();
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (inSubMenu.containsKey(player)) {
|
||||
inSubMenu.remove(player);
|
||||
inSubMenu.put(player, true);
|
||||
}
|
||||
else {
|
||||
inSubMenu.put(player, true);
|
||||
}
|
||||
event.getWhoClicked().openInventory(menu2.getInventory());
|
||||
}
|
||||
});
|
||||
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE);
|
||||
ItemMeta itemMeta = glass.getItemMeta();
|
||||
itemMeta.setDisplayName(" ");
|
||||
glass.setDurability((short)7);
|
||||
glass.setItemMeta(itemMeta);
|
||||
/* END PAGINATION */
|
||||
|
||||
// Where appropriate, include pagination.
|
||||
if(currentPage > 0) {
|
||||
toolbarItems.put(0, backButton);
|
||||
}
|
||||
if (currentPage == 0) {
|
||||
if (toolbarItems.get(0) != null) {
|
||||
toolbarItems.remove(0);
|
||||
}
|
||||
}
|
||||
if(currentPage < getFinalPage())
|
||||
toolbarItems.put(8, nextButton);
|
||||
if (currentPage == getFinalPage()) {
|
||||
if (toolbarItems.get(8) != null) {
|
||||
toolbarItems.remove(8);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the main inventory items
|
||||
int counter = 0;
|
||||
for(int key = (currentPage * 36); key <= Collections.max(items.keySet()); key++){
|
||||
if(counter >= 36)
|
||||
break;
|
||||
|
||||
if(items.containsKey(key)) {
|
||||
inventory.setItem(counter, items.get(key).getItem());
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (currentPage < getFinalPage()) {
|
||||
if (currentPage == 0 && currentPage == getFinalPage()) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage > 0 && currentPage != getFinalPage()) {
|
||||
for (int i = 1; i < 8; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage == 0) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage == getFinalPage()) {
|
||||
for (int i = 1; i < 9; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// // Add the glass bar items.
|
||||
// int limit = 1;
|
||||
// for (int glassBarItem : glassBarItems.keySet()) {
|
||||
// if (limit >= 9)
|
||||
// break;
|
||||
// inventory.setItem(limit, glassBarItems.get(glassBarItem).getItem());
|
||||
// limit++;
|
||||
// }
|
||||
|
||||
// Finally, add the toolbar items.
|
||||
for(int toolbarItem : toolbarItems.keySet()){
|
||||
int rawSlot = toolbarItem + 36;
|
||||
inventory.setItem(rawSlot, toolbarItems.get(toolbarItem).getItem());
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias to register the Inventory listeners for a certain plugin.
|
||||
* Intended to improve code readability.
|
||||
*
|
||||
* @param plugin The Spigot plugin instance that you wish to register the listeners for.
|
||||
*/
|
||||
public static void prepare(JavaPlugin plugin){
|
||||
if(inventoryListenerGUI == null){
|
||||
inventoryListenerGUI = new InventoryListenerGUI();
|
||||
plugin.getServer().getPluginManager().registerEvents(inventoryListenerGUI, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
475
src/str/playerwarps/gui/types/PaginatedGUIAllPages.java
Normal file
475
src/str/playerwarps/gui/types/PaginatedGUIAllPages.java
Normal file
@ -0,0 +1,475 @@
|
||||
/*
|
||||
* PaginatedGUI.java
|
||||
* Copyright (c) 2017 Sam Jakob Harker
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package str.playerwarps.gui.types;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.commands.gui.GUI;
|
||||
import str.playerwarps.gui.ItemBuilder;
|
||||
import str.playerwarps.gui.buttons.GUIButton;
|
||||
import str.playerwarps.gui.buttons.InventoryCloseListener;
|
||||
import str.playerwarps.gui.buttons.InventoryListenerGUIAllPages;
|
||||
import str.playerwarps.util.TitleUpdater_1_8_R3;
|
||||
import str.playerwarps.util.Utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PaginatedGUIAllPages implements InventoryHolder {
|
||||
|
||||
/* BEGIN: CONFIGURATION */
|
||||
private static final String CHAT_PREFIX = "&6";
|
||||
private static final String NO_PREVIOUS_PAGES = "&cThere are no previous pages.";
|
||||
private static final String NO_ADDITIONAL_PAGES = "&cThere are no additional pages.";
|
||||
|
||||
private static final String PREVIOUS_PAGE = "&cPrevious Page &7(&6{previousPage}&7/&6{maxPages}&7)";
|
||||
private static final String CURRENT_PAGE = "&aPage &7(&6{currentPage}&7/&6{maxPages}&7)";
|
||||
private static final String NEXT_PAGE = "&aNext Page &7(&6{nextPage}&7/&6{maxPages}&7)";
|
||||
public static final String OWN_WARP = "&a&lYour Player Warp";
|
||||
/* END: CONFIGURATION */
|
||||
|
||||
private static InventoryListenerGUIAllPages inventoryListenerGUI;
|
||||
private InventoryCloseListener closelistener;
|
||||
private Map<Integer, GUIButton> items;
|
||||
private Map<Integer, GUIButton> toolbarItems;
|
||||
private Map<Integer, GUIButton> glassBarItems;
|
||||
private int currentPage;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates a PaginatedGUI. This is a Spigot 'Inventory Menu' that
|
||||
* will automatically add pages to accommodate additional items.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public PaginatedGUIAllPages(String name){
|
||||
items = new HashMap<>();
|
||||
toolbarItems = new HashMap<>();
|
||||
glassBarItems = new HashMap<>();
|
||||
currentPage = 0;
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public void setDisplayName(String name){
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> If your inventory's display name contains
|
||||
* color codes, this will have substituted the
|
||||
* ampersands (&)s with the rendering engine's
|
||||
* symbol (§).
|
||||
*
|
||||
* @return The inventory's display name.
|
||||
*/
|
||||
public String getDisplayName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
*
|
||||
* @param listener The listener to be executed on button click.
|
||||
*/
|
||||
public void setCloseListener(InventoryCloseListener listener){
|
||||
this.closelistener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
* This is mostly for internal use by the API and is likely not useful to you.
|
||||
*
|
||||
* @return The listener to be executed on button click.
|
||||
*/
|
||||
public InventoryCloseListener getCloseListener(){
|
||||
return closelistener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} to the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> This will place the button after the highest slot.
|
||||
* So if you have buttons in slot 0, 1 and 5, this will place the
|
||||
* added button in slot 6.
|
||||
*
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void addButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : items.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
if (items.keySet().size() == 0) {
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
else {
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
}
|
||||
|
||||
public void addBarButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : glassBarItems.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
glassBarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void setButton(int slot, GUIButton button){
|
||||
items.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
*/
|
||||
public void removeButton(int slot){
|
||||
items.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link GUIButton} in the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the GUIButton that you wish to get.
|
||||
* @return The GUIButton in the provided slot.
|
||||
*/
|
||||
public GUIButton getButton(int slot) {
|
||||
if (slot < 36) {
|
||||
if (currentPage > 0) {
|
||||
return items.get(slot + (36 * currentPage));
|
||||
}
|
||||
return items.get(slot);
|
||||
}
|
||||
else {
|
||||
return toolbarItems.get(slot - 36);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI's toolbar.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void setToolbarItem(int slot, GUIButton button) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void removeToolbarItem(int slot) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the max page is currently open as it cannot go further.)
|
||||
*/
|
||||
public boolean nextPage(){
|
||||
if(currentPage < getFinalPage()){
|
||||
currentPage++;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Decrements the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the first page is currently active as it cannot go further.)
|
||||
*/
|
||||
|
||||
public boolean previousPage(){
|
||||
if(currentPage > 0) {
|
||||
currentPage--;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias for {@link #getFinalPage()}.
|
||||
*
|
||||
* @deprecated Use {@link #getFinalPage()} instead.
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getMaxPage(){
|
||||
return getFinalPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the final page of the PaginatedGUI.
|
||||
*
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getFinalPage(){
|
||||
// Get the highest slot number.
|
||||
int slot = 0;
|
||||
for(int nextSlot : items.keySet()){
|
||||
if(nextSlot > slot){
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to make the math easier.
|
||||
double highestSlot = slot + 1;
|
||||
|
||||
// Divide by 45 and round up to get the page number.
|
||||
// Then subtract one to convert it to an index.
|
||||
return (int) Math.ceil(highestSlot / (double) 36) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias that executes {@link HumanEntity#closeInventory()} and then
|
||||
* {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* @param holder The HumanEntity that you wish to refresh the inventory for.
|
||||
*/
|
||||
public void refreshInventory(HumanEntity holder) {
|
||||
Inventory items = getInventory();
|
||||
holder.getOpenInventory().getTopInventory().setContents(items.getContents());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Spigot {@link Inventory} that represents the PaginatedGUI.
|
||||
* This can then by shown to a player using {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* This also allows getting the PaginatedGUI instance with {@link InventoryHolder#getInventory()}.
|
||||
* Used internally ({@link InventoryListenerGUI}) to get the GUIButton and therefore listener from the raw slot.
|
||||
*
|
||||
* @return The Spigot Inventory that represents the PaginatedGUI.
|
||||
*/
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
// Create an inventory (and set an appropriate size.)
|
||||
// TODO: Allow customisation of inventory size. Maybe at first, only if the inventory is not paginated.
|
||||
Inventory inventory = Bukkit.createInventory(this, (getFinalPage() > 0) ? 45 : 36, name);
|
||||
|
||||
/* BEGIN PAGINATION */
|
||||
GUIButton backButton = new GUIButton(ItemBuilder.start(Material.MELON).name(PREVIOUS_PAGE
|
||||
.replaceAll(Pattern.quote("{previousPage}"), String.valueOf(currentPage - 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage()))
|
||||
)
|
||||
.build());
|
||||
GUIButton nextButton = new GUIButton(ItemBuilder.start(Material.SPECKLED_MELON).name(NEXT_PAGE
|
||||
.replaceAll(Pattern.quote("{nextPage}"), String.valueOf(currentPage + 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage()))
|
||||
)
|
||||
.build());
|
||||
GUIButton glassPane = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)7).name(" ").build());
|
||||
glassPane.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
backButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUIAllPages menu = (PaginatedGUIAllPages) event.getClickedInventory().getHolder();
|
||||
if(!menu.previousPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_PREVIOUS_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
});
|
||||
|
||||
nextButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUIAllPages menu = (PaginatedGUIAllPages) event.getClickedInventory().getHolder();
|
||||
|
||||
if(!menu.nextPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_ADDITIONAL_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
});
|
||||
|
||||
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE);
|
||||
ItemMeta itemMeta = glass.getItemMeta();
|
||||
itemMeta.setDisplayName(" ");
|
||||
glass.setDurability((short)7);
|
||||
glass.setItemMeta(itemMeta);
|
||||
// for (int i = 28; i < 36; i++) {
|
||||
// if (inventory.getItem(i) == null)
|
||||
// inventory.setItem(i, glass);
|
||||
// }
|
||||
|
||||
/* END PAGINATION */
|
||||
|
||||
// Where appropriate, include pagination.
|
||||
if(currentPage > 0) {
|
||||
toolbarItems.put(0, backButton);
|
||||
}
|
||||
if(currentPage < getFinalPage())
|
||||
toolbarItems.put(8, nextButton);
|
||||
|
||||
// Add the main inventory items
|
||||
int counter = 0;
|
||||
for(int key = (currentPage * 36); key <= Collections.max(items.keySet()); key++){
|
||||
if(counter >= 36)
|
||||
break;
|
||||
|
||||
if(items.containsKey(key)) {
|
||||
inventory.setItem(counter, items.get(key).getItem());
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
// // Add the glass bar items.
|
||||
// int limit = 1;
|
||||
// for (int glassBarItem : glassBarItems.keySet()) {
|
||||
// if (limit >= 9)
|
||||
// break;
|
||||
// inventory.setItem(limit, glassBarItems.get(glassBarItem).getItem());
|
||||
// limit++;
|
||||
// }
|
||||
if (currentPage < getFinalPage()) {
|
||||
if (currentPage == 0 && currentPage == getFinalPage()) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage > 0 && currentPage != getFinalPage()) {
|
||||
for (int i = 1; i < 8; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage == 0) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
else if (currentPage == getFinalPage()) {
|
||||
for (int i = 1; i < 9; i++) {
|
||||
toolbarItems.put(i, glassPane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, add the toolbar items.
|
||||
for(int toolbarItem : toolbarItems.keySet()){
|
||||
int rawSlot = toolbarItem + 36;
|
||||
inventory.setItem(rawSlot, toolbarItems.get(toolbarItem).getItem());
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias to register the Inventory listeners for a certain plugin.
|
||||
* Intended to improve code readability.
|
||||
*
|
||||
* @param plugin The Spigot plugin instance that you wish to register the listeners for.
|
||||
*/
|
||||
public static void prepare(JavaPlugin plugin){
|
||||
if(inventoryListenerGUI == null){
|
||||
inventoryListenerGUI = new InventoryListenerGUIAllPages();
|
||||
plugin.getServer().getPluginManager().registerEvents(inventoryListenerGUI, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
503
src/str/playerwarps/gui/types/PaginatedGUICP.java
Normal file
503
src/str/playerwarps/gui/types/PaginatedGUICP.java
Normal file
@ -0,0 +1,503 @@
|
||||
/*
|
||||
* PaginatedGUI.java
|
||||
* Copyright (c) 2017 Sam Jakob Harker
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package str.playerwarps.gui.types;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.commands.gui.GUI;
|
||||
import str.playerwarps.gui.ItemBuilder;
|
||||
import str.playerwarps.gui.buttons.GUIButton;
|
||||
import str.playerwarps.gui.buttons.InventoryCloseListener;
|
||||
import str.playerwarps.gui.buttons.InventoryListenerGUI;
|
||||
import str.playerwarps.gui.buttons.InventoryListenerGUICP;
|
||||
import str.playerwarps.util.TitleUpdater_1_8_R3;
|
||||
import str.playerwarps.util.Utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PaginatedGUICP implements InventoryHolder {
|
||||
|
||||
/* BEGIN: CONFIGURATION */
|
||||
private static final String CHAT_PREFIX = "&6";
|
||||
private static final String NO_PREVIOUS_PAGES = "&cThere are no previous pages.";
|
||||
private static final String NO_ADDITIONAL_PAGES = "&cThere are no additional pages.";
|
||||
|
||||
private static final String PREVIOUS_PAGE = "&cPrevious Page &7(&6{previousPage}&7/&6{maxPages}&7)";
|
||||
private static final String CURRENT_PAGE = "&aPage &7(&6{currentPage}&7/&6{maxPages}&7)";
|
||||
private static final String NEXT_PAGE = "&aNext Page &7(&6{nextPage}&7/&6{maxPages}&7)";
|
||||
public static final String OWN_WARP = "&a&lYour Player Warp";
|
||||
/* END: CONFIGURATION */
|
||||
|
||||
private static InventoryListenerGUICP inventoryListenerGUI;
|
||||
private InventoryCloseListener closelistener;
|
||||
public static HashMap<Player, Boolean> inSubMenu = new HashMap<Player, Boolean>();
|
||||
private Map<Integer, GUIButton> items;
|
||||
private Map<Integer, GUIButton> toolbarItems;
|
||||
private Map<Integer, GUIButton> glassBarItems;
|
||||
private int currentPage;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Creates a PaginatedGUI. This is a Spigot 'Inventory Menu' that
|
||||
* will automatically add pages to accommodate additional items.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public PaginatedGUICP(String name){
|
||||
items = new HashMap<>();
|
||||
toolbarItems = new HashMap<>();
|
||||
glassBarItems = new HashMap<>();
|
||||
currentPage = 0;
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* Color Codes are supported (and should be prepended with an
|
||||
* ampersand [&]; e.g. &c for red.)
|
||||
*
|
||||
* @param name The desired name of the PaginatedGUI.
|
||||
*/
|
||||
public void setDisplayName(String name){
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> If your inventory's display name contains
|
||||
* color codes, this will have substituted the
|
||||
* ampersands (&)s with the rendering engine's
|
||||
* symbol (§).
|
||||
*
|
||||
* @return The inventory's display name.
|
||||
*/
|
||||
public String getDisplayName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
*
|
||||
* @param listener The listener to be executed on button click.
|
||||
*/
|
||||
public void setCloseListener(InventoryCloseListener listener){
|
||||
this.closelistener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ButtonListener} that is to be executed when the GUIButton is clicked.
|
||||
* This is mostly for internal use by the API and is likely not useful to you.
|
||||
*
|
||||
* @return The listener to be executed on button click.
|
||||
*/
|
||||
public InventoryCloseListener getCloseListener(){
|
||||
return closelistener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} to the PaginatedGUI.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* <b>Note:</b> This will place the button after the highest slot.
|
||||
* So if you have buttons in slot 0, 1 and 5, this will place the
|
||||
* added button in slot 6.
|
||||
*
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void addButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : items.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
if (items.keySet().size() == 0) {
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
else {
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
items.put(slot, button);
|
||||
}
|
||||
}
|
||||
|
||||
public void addBarButton(GUIButton button) {
|
||||
// Get the current maximum slot in the 'items' list.
|
||||
int slot = 0;
|
||||
for (int nextSlot : glassBarItems.keySet()) {
|
||||
if (nextSlot > slot) {
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to get the next maximum slot.
|
||||
slot++;
|
||||
|
||||
// Put the button in that slot.
|
||||
glassBarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
*/
|
||||
public void setButton(int slot, GUIButton button){
|
||||
items.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
*/
|
||||
public void removeButton(int slot){
|
||||
items.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link GUIButton} in the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the GUIButton that you wish to get.
|
||||
* @return The GUIButton in the provided slot.
|
||||
*/
|
||||
public GUIButton getButton(int slot) {
|
||||
if (slot < 27) {
|
||||
if (currentPage > 0) {
|
||||
return items.get(slot + (27 * currentPage));
|
||||
}
|
||||
return items.get(slot);
|
||||
}
|
||||
else {
|
||||
return toolbarItems.get(slot - 27);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link GUIButton} but places it in the desired slot in the PaginatedGUI's toolbar.
|
||||
*
|
||||
* @param slot The desired slot for the button.
|
||||
* @param button The button you wish to add.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void setToolbarItem(int slot, GUIButton button) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.put(slot, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link GUIButton} from the provided slot.
|
||||
*
|
||||
* @param slot The slot containing the button you wish to remove.
|
||||
* @throws IllegalArgumentException This will occur if the slot is less than 0 or higher than 8 (as this is outside the toolbar slot range.)
|
||||
*/
|
||||
public void removeToolbarItem(int slot) {
|
||||
if(slot < 0 || slot > 8){
|
||||
throw new IllegalArgumentException("The desired slot is outside the bounds of the toolbar slot range. [0-8]");
|
||||
}
|
||||
|
||||
toolbarItems.remove(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the max page is currently open as it cannot go further.)
|
||||
*/
|
||||
public boolean nextPage(){
|
||||
if(currentPage < getFinalPage()){
|
||||
currentPage++;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Decrements the current page.
|
||||
* You will need to refresh the inventory for those who have it open with {@link #refreshInventory(HumanEntity)}
|
||||
*
|
||||
* @return Whether or not the page could be changed (false when the first page is currently active as it cannot go further.)
|
||||
*/
|
||||
|
||||
public boolean previousPage(){
|
||||
if(currentPage > 0) {
|
||||
currentPage--;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias for {@link #getFinalPage()}.
|
||||
*
|
||||
* @deprecated Use {@link #getFinalPage()} instead.
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getMaxPage(){
|
||||
return getFinalPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the final page of the PaginatedGUI.
|
||||
*
|
||||
* @return The highest page number that can be viewed.
|
||||
*/
|
||||
public int getFinalPage(){
|
||||
// Get the highest slot number.
|
||||
int slot = 0;
|
||||
for(int nextSlot : items.keySet()){
|
||||
if(nextSlot > slot){
|
||||
slot = nextSlot;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one to make the math easier.
|
||||
double highestSlot = slot + 1;
|
||||
|
||||
// Divide by 45 and round up to get the page number.
|
||||
// Then subtract one to convert it to an index.
|
||||
return (int) Math.ceil(highestSlot / (double) 27) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the current page of the PaginatedGUI.
|
||||
*
|
||||
* @return The current page number.
|
||||
*/
|
||||
public int getCurrentPage(){
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of the current page of the PaginatedGUI.
|
||||
*
|
||||
* @return Sets the current page number to what you wish.
|
||||
*/
|
||||
public void setCurrentPage(int page){
|
||||
currentPage = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias that executes {@link HumanEntity#closeInventory()} and then
|
||||
* {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* @param holder The HumanEntity that you wish to refresh the inventory for.
|
||||
*/
|
||||
public void refreshInventory(HumanEntity holder) {
|
||||
Inventory items = getInventory();
|
||||
holder.getOpenInventory().getTopInventory().setContents(items.getContents());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Spigot {@link Inventory} that represents the PaginatedGUI.
|
||||
* This can then by shown to a player using {@link HumanEntity#openInventory(Inventory)}.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* This also allows getting the PaginatedGUI instance with {@link InventoryHolder#getInventory()}.
|
||||
* Used internally ({@link InventoryListenerGUI}) to get the GUIButton and therefore listener from the raw slot.
|
||||
*
|
||||
* @return The Spigot Inventory that represents the PaginatedGUI.
|
||||
*/
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
// Create an inventory (and set an appropriate size.)
|
||||
// TODO: Allow customisation of inventory size. Maybe at first, only if the inventory is not paginated.
|
||||
Inventory inventory = Bukkit.createInventory(this, (getFinalPage() > 0) ? 36 : 27, name);
|
||||
|
||||
/* BEGIN PAGINATION */
|
||||
GUIButton backButton = new GUIButton(ItemBuilder.start(Material.MELON).name(PREVIOUS_PAGE
|
||||
.replaceAll(Pattern.quote("{previousPage}"), String.valueOf((currentPage + 1) - 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage() + 1))
|
||||
)
|
||||
.build());
|
||||
GUIButton nextButton = new GUIButton(ItemBuilder.start(Material.SPECKLED_MELON).name(NEXT_PAGE
|
||||
.replaceAll(Pattern.quote("{nextPage}"), String.valueOf((currentPage + 1) + 1))
|
||||
.replaceAll(Pattern.quote("{maxPages}"), String.valueOf(getFinalPage() + 1))
|
||||
)
|
||||
.build());
|
||||
GUIButton glassPane = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)7).name(" ").build());
|
||||
glassPane.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
backButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUICP menu = (PaginatedGUICP) event.getClickedInventory().getHolder();
|
||||
if(!menu.previousPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_PREVIOUS_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
TitleUpdater_1_8_R3.update(player, ChatColor.translateAlternateColorCodes('&', "Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)"));
|
||||
});
|
||||
|
||||
nextButton.setListener(event -> {
|
||||
event.setCancelled(true);
|
||||
PaginatedGUICP menu = (PaginatedGUICP) event.getClickedInventory().getHolder();
|
||||
if(!menu.nextPage()){
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
CHAT_PREFIX + NO_ADDITIONAL_PAGES));
|
||||
return;
|
||||
}
|
||||
|
||||
refreshInventory(event.getWhoClicked());
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
TitleUpdater_1_8_R3.update(player, ChatColor.translateAlternateColorCodes('&', "Player Warps &7(&6" + (menu.getCurrentPage() + 1) + "/" + (menu.getFinalPage() + 1) + "&7)"));
|
||||
});
|
||||
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE);
|
||||
ItemMeta itemMeta = glass.getItemMeta();
|
||||
itemMeta.setDisplayName(" ");
|
||||
glass.setDurability((short)7);
|
||||
glass.setItemMeta(itemMeta);
|
||||
/* END PAGINATION */
|
||||
|
||||
// Where appropriate, include pagination.
|
||||
if(currentPage > 0) {
|
||||
toolbarItems.put(0, backButton);
|
||||
}
|
||||
if (currentPage == 0) {
|
||||
if (toolbarItems.get(0) != null) {
|
||||
toolbarItems.remove(0);
|
||||
}
|
||||
}
|
||||
if(currentPage < getFinalPage())
|
||||
toolbarItems.put(8, nextButton);
|
||||
if (currentPage == getFinalPage()) {
|
||||
if (toolbarItems.get(8) != null) {
|
||||
toolbarItems.remove(8);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the main inventory items
|
||||
int counter = 0;
|
||||
for(int key = (currentPage * 27); key <= Collections.max(items.keySet()); key++){
|
||||
if(counter >= 27)
|
||||
break;
|
||||
|
||||
if(items.containsKey(key)) {
|
||||
inventory.setItem(counter, items.get(key).getItem());
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
//
|
||||
// if (currentPage < getFinalPage()) {
|
||||
// if (currentPage == 0 && currentPage == getFinalPage()) {
|
||||
// for (int i = 0; i < 9; i++) {
|
||||
// toolbarItems.put(i, glassPane);
|
||||
// }
|
||||
// }
|
||||
// else if (currentPage > 0 && currentPage != getFinalPage()) {
|
||||
// for (int i = 1; i < 8; i++) {
|
||||
// toolbarItems.put(i, glassPane);
|
||||
// }
|
||||
// }
|
||||
// else if (currentPage == 0) {
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// toolbarItems.put(i, glassPane);
|
||||
// }
|
||||
// }
|
||||
// else if (currentPage == getFinalPage()) {
|
||||
// for (int i = 1; i < 9; i++) {
|
||||
// toolbarItems.put(i, glassPane);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Add the glass bar items.
|
||||
// int limit = 1;
|
||||
// for (int glassBarItem : glassBarItems.keySet()) {
|
||||
// if (limit >= 9)
|
||||
// break;
|
||||
// inventory.setItem(limit, glassBarItems.get(glassBarItem).getItem());
|
||||
// limit++;
|
||||
// }
|
||||
|
||||
// Finally, add the toolbar items.
|
||||
for(int toolbarItem : toolbarItems.keySet()){
|
||||
int rawSlot = toolbarItem + 27;
|
||||
inventory.setItem(rawSlot, toolbarItems.get(toolbarItem).getItem());
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply an alias to register the Inventory listeners for a certain plugin.
|
||||
* Intended to improve code readability.
|
||||
*
|
||||
* @param plugin The Spigot plugin instance that you wish to register the listeners for.
|
||||
*/
|
||||
public static void prepare(JavaPlugin plugin){
|
||||
if(inventoryListenerGUI == null){
|
||||
inventoryListenerGUI = new InventoryListenerGUICP();
|
||||
plugin.getServer().getPluginManager().registerEvents(inventoryListenerGUI, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
222
src/str/playerwarps/listener/InventoryListener.java
Normal file
222
src/str/playerwarps/listener/InventoryListener.java
Normal file
@ -0,0 +1,222 @@
|
||||
package str.playerwarps.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
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.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryInteractEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.util.Utils;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
// static List<Material> filterList = new ArrayList<>();
|
||||
public List<String> filterList = PlayerWarps.get().getCustomData().getStringList("Blocked-Items");
|
||||
|
||||
@EventHandler
|
||||
public void onInventory1(InventoryClickEvent event) {
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
for (int i = 0; i < filterList.size(); i++) {
|
||||
String blacklisted = filterList.get(i);
|
||||
Material filter = Material.getMaterial(blacklisted);
|
||||
|
||||
// if (event.getAction() == InventoryAction.DROP_ONE_SLOT || event.getAction() == InventoryAction.DROP_ALL_SLOT || event.getAction() == InventoryAction.DROP_ALL_CURSOR || event.getAction() == InventoryAction.DROP_ONE_CURSOR) {
|
||||
// event.setCancelled(true);
|
||||
// Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
// }
|
||||
if (event.getCurrentItem() == null || event.getCursor() == null) {
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
else if (!event.getCurrentItem().getType().equals(filter) || !event.getInventory().contains(filter) || !event.getCursor().getType().equals(filter)) {
|
||||
continue;
|
||||
}
|
||||
else if (event.getInventory().contains(filter) || event.getCurrentItem().getType().equals(filter) || event.getCursor().getType().equals(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else if (event.getClickedInventory().contains(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onMove(PlayerMoveEvent event) {
|
||||
// Player p = (Player) event.getPlayer();
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
// for (int i = 0; i < filterList.size(); i++) {
|
||||
// String blacklisted = filterList.get(i);
|
||||
// Material filter = Material.getMaterial(blacklisted);
|
||||
// if (p.getInventory().getContents() != null) {
|
||||
// if (p.getInventory().contains(filter)) {
|
||||
// event.setCancelled(true);
|
||||
// p.getInventory().remove(filter);
|
||||
// Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
// }
|
||||
// else {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
@EventHandler
|
||||
public void onInventory5(InventoryCreativeEvent event) {
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
for (int i = 0; i < filterList.size(); i++) {
|
||||
String blacklisted = filterList.get(i);
|
||||
Material filter = Material.getMaterial(blacklisted);
|
||||
|
||||
if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY || event.getAction() == InventoryAction.COLLECT_TO_CURSOR || event.getAction() == InventoryAction.DROP_ONE_SLOT || event.getAction() == InventoryAction.DROP_ALL_SLOT || event.getAction() == InventoryAction.DROP_ALL_CURSOR || event.getAction() == InventoryAction.DROP_ONE_CURSOR || event.getAction() == InventoryAction.CLONE_STACK) {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else if (event.getCurrentItem() == null || event.getCursor() == null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (!event.getCurrentItem().getType().equals(filter) || !event.getInventory().contains(filter) || !event.getCursor().getType().equals(filter)) {
|
||||
continue;
|
||||
}
|
||||
else if (event.getInventory().contains(filter) || event.getCurrentItem().getType().equals(filter) || event.getCursor().getType().equals(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else if (event.getClickedInventory().contains(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventory3(InventoryInteractEvent event) {
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
for (int i = 0; i < filterList.size(); i++) {
|
||||
String blacklisted = filterList.get(i);
|
||||
Material filter = Material.getMaterial(blacklisted);
|
||||
|
||||
if (!event.getInventory().contains(filter)) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (event.getInventory().contains(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(PlayerInteractEvent event) {
|
||||
Player p = (Player) event.getPlayer();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
for (int i = 0; i < filterList.size(); i++) {
|
||||
String blacklisted = filterList.get(i);
|
||||
Material filter = Material.getMaterial(blacklisted);
|
||||
|
||||
if (event.getPlayer().getItemInHand().getType().equals(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onConsume(PlayerItemConsumeEvent event) {
|
||||
Player p = (Player) event.getPlayer();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
for (int i = 0; i < filterList.size(); i++) {
|
||||
String blacklisted = filterList.get(i);
|
||||
Material filter = Material.getMaterial(blacklisted);
|
||||
|
||||
if (filter != event.getItem().getType()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.getItem().getType().equals(filter)) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().getInventory().remove(filter);
|
||||
Utils.sendMessage(p, "&cYou cannot have " + filter.toString().toLowerCase() + " &cinside of your inventory right now");
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrop(PlayerDropItemEvent event) {
|
||||
Player p = (Player) event.getPlayer();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot drop items while building a warp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1369
src/str/playerwarps/listener/PlayerListener.java
Normal file
1369
src/str/playerwarps/listener/PlayerListener.java
Normal file
File diff suppressed because it is too large
Load Diff
648
src/str/playerwarps/listener/WarpBlockListener.java
Normal file
648
src/str/playerwarps/listener/WarpBlockListener.java
Normal file
@ -0,0 +1,648 @@
|
||||
package str.playerwarps.listener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.gui.ItemBuilder;
|
||||
import str.playerwarps.gui.buttons.GUIButton;
|
||||
import str.playerwarps.gui.types.PaginatedGUI;
|
||||
import str.playerwarps.gui.types.PaginatedGUIAllPages;
|
||||
import str.playerwarps.gui.types.PaginatedGUICP;
|
||||
import str.playerwarps.util.Utils;
|
||||
import str.playerwarps.util.Zone;
|
||||
|
||||
public class WarpBlockListener implements Listener {
|
||||
|
||||
public static List<Location> placedBlock = new ArrayList<Location>();
|
||||
public static List<Location> walls = new ArrayList<Location>();
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (p.getWorld() == Bukkit.getWorld("PlayerWarps-World")) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null) {
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
OfflinePlayer player = (OfflinePlayer) Bukkit.getOfflinePlayer(uuid);
|
||||
Location loc;
|
||||
Location loc2;
|
||||
Location loc3;
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + uuid.toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".xb") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".yb") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".zb") != null) {
|
||||
loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
if (Zone.contains(event.getPlayer().getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
if (player.getName() == p.getName()) {
|
||||
if (Utils.getPlayerWarpLocation(p.getUniqueId().toString()) != null) {
|
||||
loc3 = Utils.getPlayerWarpLocation(p.getUniqueId().toString());
|
||||
if (Zone.contains(event.getPlayer().getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Approved") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
Block b = event.getBlock();
|
||||
ItemStack block = new ItemStack(b.getType(), 1, b.getData());
|
||||
|
||||
if (b.getType() == Material.GLASS || b.getType() == Material.GLOWSTONE || b.getType() == Material.BEACON) {
|
||||
if (!placedBlock.contains(b.getLocation())) {
|
||||
if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Disallow") {
|
||||
Utils.sendMessage(p, "&cYou cannot break the perimeter of your warp.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "SafeZone") {
|
||||
Utils.sendMessage(p, "&cYou cannot break the warp safezone.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot break this block.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (placedBlock.contains(b.getLocation())) {
|
||||
placedBlock.remove(b.getLocation());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Disallow") {
|
||||
Utils.sendMessage(p, "&cYou cannot break the perimeter of your warp.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "SafeZone") {
|
||||
Utils.sendMessage(p, "&cYou cannot break the warp safezone.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Allow") {
|
||||
return;
|
||||
}
|
||||
// WORKING CODE FFS Location loc1 = Utils.getPlayerWarpLocation(p.getUniqueId().toString()).subtract(24.500, 15.00000, -2.500);
|
||||
// Location loc11 = loc1.clone().add(49, 58, 49);
|
||||
// int xLow = Math.min(loc1.getBlockX(), loc11.getBlockX());
|
||||
// int xHigh = Math.max(loc1.getBlockX(), loc11.getBlockX());
|
||||
//
|
||||
// int yLow = Math.min(loc1.getBlockY(), loc11.getBlockY());
|
||||
// int yHigh = Math.max(loc1.getBlockY(), loc11.getBlockY());
|
||||
//
|
||||
// int zLow = Math.min(loc1.getBlockZ(), loc11.getBlockZ());
|
||||
// int zHigh = Math.max(loc1.getBlockZ(), loc11.getBlockZ());
|
||||
//
|
||||
//
|
||||
//
|
||||
// for (int x = xLow; x <= xHigh; x++) {
|
||||
// for (int y = yLow; y <= yHigh; y++) {
|
||||
// for (int z = zLow; z <= zHigh - 1; z++) {
|
||||
// if (x == zLow || y == zLow || z == zLow || x == xHigh - 1 || y == yHigh - 1 || z == zHigh) {
|
||||
// if (b.getType() == Material.GRASS) {
|
||||
// return;
|
||||
// }
|
||||
// if (b.getX() == x && b.getY() == y && b.getZ() == z) {
|
||||
// Utils.sendMessage(p, "&cYou cannot break the perimeter of your warp.");
|
||||
// event.setCancelled(true);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot break blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot break blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot break blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (p.getWorld() == Bukkit.getWorld("PlayerWarps-World")) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null) {
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
OfflinePlayer player = (OfflinePlayer) Bukkit.getOfflinePlayer(uuid);
|
||||
Location loc;
|
||||
Location loc2;
|
||||
Location loc3;
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + uuid.toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".xb") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".yb") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".zb") != null) {
|
||||
loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
if (Zone.contains(event.getPlayer().getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
if (player.getName() == p.getName()) {
|
||||
if (Utils.getPlayerWarpLocation(p.getUniqueId().toString()) != null) {
|
||||
loc3 = Utils.getPlayerWarpLocation(p.getUniqueId().toString());
|
||||
if (Zone.contains(event.getPlayer().getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Approved") == null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
Block b = event.getBlock();
|
||||
if (b.getType() == Material.GLASS || b.getType() == Material.GLOWSTONE) {
|
||||
if (!placedBlock.contains(b.getLocation())) {
|
||||
if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Disallow") {
|
||||
Utils.sendMessage(p, "&cYou cannot build on the perimeter of your warp.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "SafeZone") {
|
||||
Utils.sendMessage(p, "&cYou cannot build in the warp safezone.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
placedBlock.add(b.getLocation());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Disallow") {
|
||||
Utils.sendMessage(p, "&cYou cannot build on the perimeter of your warp.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "SafeZone") {
|
||||
Utils.sendMessage(p, "&cYou cannot build in the warp safezone.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (PlayerWarps.get().getWarpBox().testForWarpWalls(p, b) == "Allow") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot place blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot place blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot place blocks inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onChestOpen(PlayerInteractEvent event) {
|
||||
// Player p = (Player) event.getPlayer();
|
||||
// if (event.getItem() == null || event.getItem().getType() == Material.AIR) return;
|
||||
// if (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.ENDER_CHEST || event.getClickedBlock().getType() == Material.TRAPPED_CHEST) {
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
// event.setCancelled(true);
|
||||
// Utils.sendMessage(p, "&cYou cannot open containers inside of a playerwarp.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EventHandler
|
||||
// public void onBeaconOpen(PlayerInteractEvent event) {
|
||||
// Player p = (Player) event.getPlayer();
|
||||
// if (event.getItem() == null || event.getItem().getType() == Material.AIR) return;
|
||||
// if (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.ENDER_CHEST || event.getClickedBlock().getType() == Material.TRAPPED_CHEST) {
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
// event.setCancelled(true);
|
||||
// Utils.sendMessage(p, "&cYou cannot open containers inside of a playerwarp.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (event.getClickedBlock().getType() == Material.BEACON) {
|
||||
// event.setCancelled(true);
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null) {
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) != null) {
|
||||
// if (Utils.getPlayerWarpLocation(p.getUniqueId().toString()) != null) {
|
||||
// Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
// for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
// UUID uuid = UUID.fromString(it.next());
|
||||
// OfflinePlayer player = (OfflinePlayer) Bukkit.getOfflinePlayer(uuid);
|
||||
// Location loc = Utils.getPlayerWarpLocation(uuid.toString());
|
||||
// if (Zone.contains(p.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
// if (player.getUniqueId() == p.getUniqueId()) {
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
// PaginatedGUICP controlPanel = new PaginatedGUICP("Warp Create: Control Panel");
|
||||
// GUIButton glassPane = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)15).name(" ").build());
|
||||
// glassPane.setListener(event1 -> {
|
||||
// event1.setCancelled(true);
|
||||
// });
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// controlPanel.setButton(i, glassPane);
|
||||
// }
|
||||
// List<String> infoLore = new ArrayList<String>();
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Need-Approval") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("false")) {
|
||||
// infoLore.add("&7Status: &aApproved");
|
||||
// }
|
||||
// else {
|
||||
// infoLore.add("&7Status: &cUnapproved");
|
||||
// }
|
||||
// if (Utils.getEditTime(p.getUniqueId().toString()) != 0) {
|
||||
// infoLore.add("&7Banked Edit Time: &f" + Utils.formatSeconds(Long.valueOf(Utils.getEditTime(p.getUniqueId().toString()))));
|
||||
// }
|
||||
// else {
|
||||
// infoLore.add("&7Banked Edit Time: &f" + Utils.getEditTime(p.getUniqueId().toString()) + "s");
|
||||
// }
|
||||
// GUIButton info = new GUIButton(ItemBuilder.start(Material.PAPER).name("&a&lInformation").lore(infoLore).build());
|
||||
// info.setListener(event2 -> {
|
||||
// event2.setCancelled(true);
|
||||
// });
|
||||
// controlPanel.addButton(info);
|
||||
// for (int i = 11; i < 15; i++) {
|
||||
// controlPanel.setButton(i, glassPane);
|
||||
// }
|
||||
// List<String> transactionsLore = new ArrayList<String>();
|
||||
// transactionsLore.add("&7The last 10 time transactions of your warp,");
|
||||
// transactionsLore.add("&7this is sorted latest to oldest.");
|
||||
// if (Utils.getTransactions(p.getUniqueId().toString()) != false) {
|
||||
// transactionsLore.add("");
|
||||
// List<String> t = (List<String>) PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + p.getUniqueId().toString());
|
||||
// int count = 1;
|
||||
// for (int i = 0; i < PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + p.getUniqueId().toString()).size(); i++) {
|
||||
// transactionsLore.add("&e&l" + count + ") " + PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + p.getUniqueId().toString()).get(i));
|
||||
// count++;
|
||||
// }
|
||||
// }
|
||||
// GUIButton transactions = new GUIButton(ItemBuilder.start(Material.EMPTY_MAP).name("&a&lTransactions").lore(transactionsLore).build());
|
||||
// transactions.setListener(event3 -> {
|
||||
// event3.setCancelled(true);
|
||||
// });
|
||||
// controlPanel.addButton(transactions);
|
||||
// List<String> editWarpLore = new ArrayList<String>();
|
||||
// if (Utils.getEditTime(p.getUniqueId().toString()) == 0) {
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&7You currently cannot start editing your warp");
|
||||
// editWarpLore.add("&7as you have no edit time available.");
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&c[You must have remaining time to edit your warp]");
|
||||
// }
|
||||
// else {
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&7This will allow you to enter edit mode on your warp.");
|
||||
// editWarpLore.add("&7Time Remaining: &f" + Utils.formatSeconds(Long.valueOf(Utils.getEditTime(p.getUniqueId().toString()))));
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&a[Click to start editing your warp]");
|
||||
// }
|
||||
// GUIButton editWarp = new GUIButton(ItemBuilder.start(Material.BOOK_AND_QUILL).name("&a&lEdit Warp").lore(editWarpLore).build());
|
||||
// editWarp.setListener(event4 -> {
|
||||
// event4.setCancelled(true);
|
||||
// if (event4.getRawSlot() < event4.getInventory().getSize()) {
|
||||
// if (Utils.getEditTime(p.getUniqueId().toString()) != 0) {
|
||||
// if (p.getOpenInventory() != null) p.closeInventory();
|
||||
// PlayerWarps.get().getWorldSetup().createVoidWorld(p, true, Utils.getEditTime(p.getUniqueId().toString()));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// controlPanel.addButton(editWarp);
|
||||
// for (int i = 17; i < 27; i++) {
|
||||
// controlPanel.setButton(i, glassPane);
|
||||
// }
|
||||
// p.openInventory(controlPanel.getInventory());
|
||||
// }
|
||||
// else {
|
||||
// PaginatedGUICP controlPanel = new PaginatedGUICP("Warp Create: Control Panel");
|
||||
// GUIButton glassPane = new GUIButton(ItemBuilder.start(Material.STAINED_GLASS_PANE).data((short)15).name(" ").build());
|
||||
// glassPane.setListener(event1 -> {
|
||||
// event1.setCancelled(true);
|
||||
// });
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// controlPanel.setButton(i, glassPane);
|
||||
// }
|
||||
// List<String> infoLore = new ArrayList<String>();
|
||||
// if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Need-Approval") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + p.getUniqueId().toString() + ".Need-Approval").equalsIgnoreCase("false")) {
|
||||
// infoLore.add("&7Status: &aApproved");
|
||||
// }
|
||||
// else {
|
||||
// infoLore.add("&7Status: &cUnapproved");
|
||||
// }
|
||||
// if (Utils.getEditTime(p.getUniqueId().toString()) != 0) {
|
||||
// infoLore.add("&7Banked Edit Time: &f" + Utils.formatSeconds(Long.valueOf(Utils.getEditTime(p.getUniqueId().toString()))));
|
||||
// }
|
||||
// else {
|
||||
// infoLore.add("&7Banked Edit Time: &f" + Utils.getEditTime(p.getUniqueId().toString()) + "s");
|
||||
// }
|
||||
// GUIButton info = new GUIButton(ItemBuilder.start(Material.PAPER).name("&a&lInformation").lore(infoLore).build());
|
||||
// info.setListener(event2 -> {
|
||||
// event2.setCancelled(true);
|
||||
// });
|
||||
// controlPanel.addButton(info);
|
||||
// controlPanel.addButton(glassPane);
|
||||
// GUIButton editSpawnRoomWalls = new GUIButton(ItemBuilder.start(Material.BRICK).name("&e&lComing Soon").build());
|
||||
// editSpawnRoomWalls.setListener(event3 -> {
|
||||
// event3.setCancelled(true);
|
||||
// });
|
||||
// // List<String> spawnRoomWallsLore = new ArrayList<String>();
|
||||
// // spawnRoomWallsLore.add("&7Change what the wall material composition");
|
||||
// // spawnRoomWallsLore.add("&7of your warp are made out of.");
|
||||
// // spawnRoomWallsLore.add("");
|
||||
// // spawnRoomWallsLore.add("&a[Left click to edit Spawn Room walls]");
|
||||
// // GUIButton editSpawnRoomWalls = new GUIButton(ItemBuilder.start(Material.BRICK).name("&e&lEdit Spawn Room Walls").lore(spawnRoomWallsLore).build());
|
||||
// // editSpawnRoomWalls.setListener(event3 -> {
|
||||
// // event3.setCancelled(true);
|
||||
// // if (event3.getRawSlot() < event3.getInventory().getSize()) {
|
||||
// // PaginatedGUIAllPages controlPanelSR = new PaginatedGUIAllPages("Warp Create Walls: Spawn Room");
|
||||
// // PaginatedGUI.inSubMenu.put(p, true);
|
||||
// // for (int i = 0; i < 4; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // GUIButton paper = new GUIButton(ItemBuilder.start(Material.PAPER).build());
|
||||
// // paper.setListener(e -> {
|
||||
// // e.setCancelled(true);
|
||||
// // });
|
||||
// // controlPanelSR.addButton(paper);
|
||||
// // for (int i = 0; i < 19; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // double chance = 100;
|
||||
// //// if (controlPanelSR.getButton(19) != null) {
|
||||
// //// chance = 100 / 2;
|
||||
// //// }
|
||||
// //// else {
|
||||
// //// chance = 100;
|
||||
// //// }
|
||||
// //// if (controlPanelSR.getButton(20) != null) {
|
||||
// //// chance = 100 / 3;
|
||||
// //// }
|
||||
// //// else {
|
||||
// //// chance = 100 / 2;
|
||||
// //// }
|
||||
// // List<String> blockLore = new ArrayList<String>();
|
||||
// // blockLore.add("&7Usage Chance: &a" + chance + "%");
|
||||
// // blockLore.add("");
|
||||
// // blockLore.add("&c[Click to remove]");
|
||||
// // GUIButton glass = new GUIButton(ItemBuilder.start(Material.GLASS).lore(blockLore).build());
|
||||
// // glass.setListener(e2 -> {
|
||||
// // e2.setCancelled(true);
|
||||
// // if (e2.getRawSlot() < e2.getInventory().getSize()) {
|
||||
// // if (controlPanelSR.getButton(21) != null || controlPanelSR.getButton(22) != null || controlPanelSR.getButton(23) != null || controlPanelSR.getButton(24) != null || controlPanelSR.getButton(25) != null || controlPanelSR.getButton(26) != null) {
|
||||
// // controlPanelSR.removeButton(20);
|
||||
// // }
|
||||
// // else {
|
||||
// // Utils.sendMessage(p, "&cYou cannot remove this as their has to be at least 1 block selected.");
|
||||
// // }
|
||||
// // }
|
||||
// // });
|
||||
// // for (int i = 27; i < 36; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // controlPanelSR.setCloseListener(e1 -> {
|
||||
// // Bukkit.getScheduler().runTaskLater(PlayerWarps.get(), new Runnable() {
|
||||
// // public void run() {
|
||||
// // if (PaginatedGUI.inSubMenu.get(p) == true) {
|
||||
// // PaginatedGUI.inSubMenu.remove(p);
|
||||
// // }
|
||||
// // if (p.getOpenInventory() != null) p.closeInventory();
|
||||
// // p.openInventory(controlPanel.getInventory());
|
||||
// // Utils.sendMessage(p, "&e&lWarp Create &aSpawn room walls have been updated!");
|
||||
// // }
|
||||
// // }, 1L);
|
||||
// // });
|
||||
// // }
|
||||
// // });
|
||||
// // controlPanel.addButton(editSpawnRoomWalls);
|
||||
// controlPanel.addButton(editSpawnRoomWalls);
|
||||
// controlPanel.addButton(glassPane);
|
||||
// GUIButton editWarpRoomWalls = new GUIButton(ItemBuilder.start(Material.BRICK).name("&e&lComing Soon").build());
|
||||
// editWarpRoomWalls.setListener(event4 -> {
|
||||
// event4.setCancelled(true);
|
||||
// });
|
||||
// // List<String> warpRoomWallsLore = new ArrayList<String>();
|
||||
// // warpRoomWallsLore.add("&7Change what the wall material composition");
|
||||
// // warpRoomWallsLore.add("&7of your warp are made out of.");
|
||||
// // warpRoomWallsLore.add("");
|
||||
// // warpRoomWallsLore.add("&a[Left click to edit Warp Room walls]");
|
||||
// // GUIButton editWarpRoomWalls = new GUIButton(ItemBuilder.start(Material.BRICK).name("&e&lEdit Warp Room Walls").lore(warpRoomWallsLore).build());
|
||||
// // editWarpRoomWalls.setListener(event4 -> {
|
||||
// // event4.setCancelled(true);
|
||||
// // if (event4.getRawSlot() < event4.getInventory().getSize()) {
|
||||
// // PaginatedGUIAllPages controlPanelSR = new PaginatedGUIAllPages("Warp Create Walls: Warp Room");
|
||||
// // PaginatedGUI.inSubMenu.put(p, true);
|
||||
// // for (int i = 0; i < 4; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // GUIButton paper = new GUIButton(ItemBuilder.start(Material.PAPER).build());
|
||||
// // paper.setListener(e -> {
|
||||
// // e.setCancelled(true);
|
||||
// // });
|
||||
// // controlPanelSR.addButton(paper);
|
||||
// // for (int i = 0; i < 19; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // double chance = 100;
|
||||
// //// if (controlPanelSR.getButton(19) != null) {
|
||||
// //// chance = 100 / 2;
|
||||
// //// }
|
||||
// //// else {
|
||||
// //// chance = 100;
|
||||
// //// }
|
||||
// //// if (controlPanelSR.getButton(20) != null) {
|
||||
// //// chance = 100 / 3;
|
||||
// //// }
|
||||
// //// else {
|
||||
// //// chance = 100 / 2;
|
||||
// //// }
|
||||
// // List<String> blockLore = new ArrayList<String>();
|
||||
// // blockLore.add("&7Usage Chance: &a" + chance + "%");
|
||||
// // blockLore.add("");
|
||||
// // blockLore.add("&c[Click to remove]");
|
||||
// // GUIButton glass = new GUIButton(ItemBuilder.start(Material.GLASS).lore(blockLore).build());
|
||||
// // glass.setListener(e2 -> {
|
||||
// // e2.setCancelled(true);
|
||||
// // if (e2.getRawSlot() < e2.getInventory().getSize()) {
|
||||
// // if (controlPanelSR.getButton(21) != null || controlPanelSR.getButton(22) != null || controlPanelSR.getButton(23) != null || controlPanelSR.getButton(24) != null || controlPanelSR.getButton(25) != null || controlPanelSR.getButton(26) != null) {
|
||||
// // controlPanelSR.removeButton(20);
|
||||
// // }
|
||||
// // else {
|
||||
// // Utils.sendMessage(p, "&cYou cannot remove this as their has to be at least 1 block selected.");
|
||||
// // }
|
||||
// // }
|
||||
// // });
|
||||
// // controlPanelSR.addButton(glass);
|
||||
// // for (int i = 27; i < 36; i++) {
|
||||
// // controlPanelSR.setButton(i, glassPane);
|
||||
// // }
|
||||
// // controlPanelSR.setCloseListener(e1 -> {
|
||||
// // Bukkit.getScheduler().runTaskLater(PlayerWarps.get(), new Runnable() {
|
||||
// // public void run() {
|
||||
// // if (PaginatedGUI.inSubMenu.get(p) == true) {
|
||||
// // PaginatedGUI.inSubMenu.remove(p);
|
||||
// // }
|
||||
// // if (p.getOpenInventory() != null) p.closeInventory();
|
||||
// // p.openInventory(controlPanel.getInventory());
|
||||
// // Utils.sendMessage(p, "&e&lWarp Create &aWarp room walls have been updated!");
|
||||
// // }
|
||||
// // }, 1L);
|
||||
// // });
|
||||
// // if (p.getOpenInventory() != null) p.closeInventory();
|
||||
// // p.openInventory(controlPanelSR.getInventory());
|
||||
// // }
|
||||
// // });
|
||||
// controlPanel.addButton(editWarpRoomWalls);
|
||||
// controlPanel.addButton(glassPane);
|
||||
// List<String> editWarpLore = new ArrayList<String>();
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&7This will make it so you stop editing your warp,");
|
||||
// editWarpLore.add("&7and it will withdraw however much time you've used,");
|
||||
// editWarpLore.add("&7and store the remaining time for further use.");
|
||||
// editWarpLore.add("");
|
||||
// editWarpLore.add("&a[Click to stop editing your warp]");
|
||||
// GUIButton editWarp = new GUIButton(ItemBuilder.start(Material.BOOK_AND_QUILL).name("&e&lStop Editing").lore(editWarpLore).build());
|
||||
// editWarp.setListener(event5 -> {
|
||||
// event5.setCancelled(true);
|
||||
// if (event5.getRawSlot() < event5.getInventory().getSize()) {
|
||||
// if (p.getOpenInventory() != null) p.closeInventory();
|
||||
// Utils.removeWarpBuilding(p.getUniqueId().toString());
|
||||
// }
|
||||
// });
|
||||
// controlPanel.addButton(editWarp);
|
||||
// for (int i = 17; i < 27; i++) {
|
||||
// controlPanel.setButton(i, glassPane);
|
||||
// }
|
||||
// p.openInventory(controlPanel.getInventory());
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// Utils.sendMessage(p, "&cYou must be the owner of this warp create to access the control panel.");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// Utils.sendMessage(p, "&cYou must be the owner of this warp create to access the control panel.");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (event.getItem() == null || event.getItem().getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
if (p.getWorld() == Bukkit.getWorld("PlayerWarps-World")) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null) {
|
||||
if (event.getItem().getType() == Material.WATER_BUCKET || event.getItem().getType() == Material.LAVA_BUCKET) {
|
||||
if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
Utils.sendMessage(p, "&cYou cannot place liquids inside of a playerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (p.getWorld().getName().startsWith("PlayerWarp") && !p.getWorld().getName().contains(p.getUniqueId().toString())) {
|
||||
// if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + p.getUniqueId().toString()) == null) {
|
||||
// if (event.getItem().getType() == Material.WATER_BUCKET || event.getItem().getType() == Material.LAVA_BUCKET) {
|
||||
// if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// event.setCancelled(true);
|
||||
// Utils.sendMessage(p, "&cYou cannot place blocks inside of a playerwarp.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (event.getItem().getType() == Material.WATER_BUCKET || event.getItem().getType() == Material.LAVA_BUCKET) {
|
||||
// if (p.hasPermission("playerwarps.bypass-regions")) {
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// event.setCancelled(true);
|
||||
// Utils.sendMessage(p, "&cYou cannot place blocks inside of a playerwarp.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
665
src/str/playerwarps/listener/WorldListener.java
Normal file
665
src/str/playerwarps/listener/WorldListener.java
Normal file
@ -0,0 +1,665 @@
|
||||
package str.playerwarps.listener;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
import str.playerwarps.util.ScoreboardWrapper;
|
||||
import str.playerwarps.util.Utils;
|
||||
import str.playerwarps.util.Zone;
|
||||
|
||||
public class WorldListener implements Listener {
|
||||
|
||||
|
||||
private static BukkitTask scoreboard;
|
||||
|
||||
public static HashMap<Player, Boolean> toggleBuild = new HashMap<Player, Boolean>();
|
||||
public static HashMap<Player, Boolean> building = new HashMap<Player, Boolean>();
|
||||
public static HashMap<OfflinePlayer, Boolean> ready = new HashMap<OfflinePlayer, Boolean>();
|
||||
public static HashMap<Player, Boolean> prevent = new HashMap<Player, Boolean>();
|
||||
public static HashMap<Player, Boolean> confirm = new HashMap<Player, Boolean>();
|
||||
|
||||
public static void createVoidWorld(Player player, boolean notify, int timelimit) {
|
||||
String worldname = "PlayerWarps-World";
|
||||
Location loc;
|
||||
Location loc2;
|
||||
World mainworld = Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world"));
|
||||
if (Bukkit.getWorld(worldname) != null) {
|
||||
String UUID = player.getUniqueId().toString();
|
||||
if (Utils.getPlayerWarpLocation(UUID) != null) {
|
||||
Location loc1 = Utils.getPlayerWarpLocation(UUID);
|
||||
for (Player players : Bukkit.getWorld(worldname).getPlayers()) {
|
||||
if (!players.getName().equalsIgnoreCase(player.getName())) {
|
||||
if (mainworld != null) {
|
||||
if (Zone.contains(players.getLocation(), loc1.getBlockX() + 25, loc1.getBlockX() + 20 - 69, -7, 66)) {
|
||||
players.teleport(mainworld.getSpawnLocation());
|
||||
Utils.sendMessage(players, "&6" + player.getName() + " &eis editing their playerwarp!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.teleport(loc1);
|
||||
Utils.saveEditingWarp(UUID);
|
||||
}
|
||||
|
||||
|
||||
player.getInventory().clear();
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
for (PotionEffect effects : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(effects.getType());
|
||||
}
|
||||
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've started to edit your warp with &6" + Utils.formatSeconds(timelimit) + " &eremaining.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou may open the control panel to stop editing your warp.");
|
||||
ScoreboardWrapper initSB1 = new ScoreboardWrapper(Utils.replace(PlayerWarps.get().getCustomData().getString("Server-name")));
|
||||
initSB1.addLine(Utils.replace("&7&m-------------------"));
|
||||
initSB1.addLine(Utils.replace("&6&lWarp Create"));
|
||||
initSB1.addLine(Utils.replace(" &e&l* &fTime Available:"));
|
||||
initSB1.addBlankSpace();
|
||||
initSB1.addBlankSpace();
|
||||
initSB1.addLine(Utils.replace("&7You can stop editing"));
|
||||
initSB1.addLine(Utils.replace("&7by opening the"));
|
||||
initSB1.addLine(Utils.replace("&7control panel."));
|
||||
initSB1.addLine(Utils.replace("&7&m-------------------"));
|
||||
if (PlayerWarps.get().getFeatherboardSupport()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "fb off " + player.getName());
|
||||
}
|
||||
player.setScoreboard(initSB1.getScoreboard());
|
||||
Utils.saveWarpBuilding(UUID);
|
||||
new BukkitRunnable() {
|
||||
int seconds = timelimit;
|
||||
@Override
|
||||
public void run() {
|
||||
if (seconds % 60 == 0) {
|
||||
Utils.sendMessage(player, "&6&lWarp Create &6" + Utils.formatSeconds(seconds) + " &aleft.");
|
||||
}
|
||||
if (seconds > 0) {
|
||||
seconds--;
|
||||
String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
initSB1.setLine(3, Utils.replace(" &e&l* &3" + formatBoardSec));
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
this.cancel();
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), seconds, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
endSb(player);
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
this.cancel();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
endSb(player);
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) != null) {
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), seconds, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've ended your editing session in your warp with &6" + Utils.formatSeconds(seconds) + " &eremaining for further use.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou may open the control panel to start editing your warp again.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eStaff will approve your warp once they look at it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.cancel();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
endSb(player);
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) != null) {
|
||||
Utils.deleteWarpTransactions(player.getUniqueId().toString());
|
||||
Utils.sendMessage(player, "&6&lWarp Create &cYour warp was forcefully deleted.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &cPlease contact staff if you think this was a mistake.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.cancel();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), 0, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've ended your editing session in your warp with &6" + Utils.formatSeconds(seconds) + " &eremaining.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eStaff will approve your warp once they look at it.");
|
||||
endSb(player);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
toggleBuild.put(player, true);
|
||||
building.put(player, true);
|
||||
prevent.put(player, true);
|
||||
player.setScoreboard(initSB1.getScoreboard());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else {
|
||||
|
||||
player.getInventory().clear();
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
for (PotionEffect effects : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(effects.getType());
|
||||
}
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've started to edit your warp with &6" + Utils.formatSeconds(timelimit) + " &eremaining.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou may open the control panel to stop editing your warp.");
|
||||
ScoreboardWrapper initSB1 = new ScoreboardWrapper(Utils.replace(PlayerWarps.get().getCustomData().getString("Server-name")));
|
||||
initSB1.addLine(Utils.replace("&7&m-------------------"));
|
||||
initSB1.addLine(Utils.replace("&6&lWarpCreate"));
|
||||
initSB1.addLine(Utils.replace(" &e&l* &fTime Available:"));
|
||||
initSB1.addBlankSpace();
|
||||
initSB1.addBlankSpace();
|
||||
initSB1.addLine(Utils.replace("&7You can stop editing"));
|
||||
initSB1.addLine(Utils.replace("&7by opening the"));
|
||||
initSB1.addLine(Utils.replace("&7control panel."));
|
||||
initSB1.addLine(Utils.replace("&7&m-------------------"));
|
||||
if (PlayerWarps.get().getFeatherboardSupport()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "fb off " + player.getName());
|
||||
}
|
||||
player.setScoreboard(initSB1.getScoreboard());
|
||||
new BukkitRunnable() {
|
||||
int seconds = timelimit;
|
||||
@Override
|
||||
public void run() {
|
||||
if (seconds % 60 == 0) {
|
||||
Utils.sendMessage(player, "&6&lWarp Create &6" + Utils.formatSeconds(seconds) + " &aleft.");
|
||||
}
|
||||
if (seconds > 0) {
|
||||
seconds--;
|
||||
String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
initSB1.setLine(3, Utils.replace(" &e&l* &3" + formatBoardSec));
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
this.cancel();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
player.getOpenInventory().getBottomInventory().clear();
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), seconds, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
endSb(player);
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + player.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Building") != null && PlayerWarps.get().getCustomData().getString("Warps-Created-By." + player.getUniqueId().toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
this.cancel();
|
||||
endSb(player);
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) != null) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
player.getOpenInventory().getBottomInventory().clear();
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), seconds, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've ended your editing session in your warp with &6" + Utils.formatSeconds(seconds) + " &eremaining for further use.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou may open the control panel to start editing your warp again.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eStaff will approve your warp once they look at it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.cancel();
|
||||
endSb(player);
|
||||
if (Bukkit.getServer().getPlayer(player.getName()) != null) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
player.getOpenInventory().getBottomInventory().clear();
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
Utils.deleteWarpTransactions(player.getUniqueId().toString());
|
||||
Utils.sendMessage(player, "&6&lWarp Create &cYour warp was forcefully deleted.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &cPlease contact staff if you think this was a mistake.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.cancel();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
player.getOpenInventory().getBottomInventory().clear();
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
Date now = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
|
||||
|
||||
Utils.saveEditTime(player.getUniqueId().toString(), 0, "(-" + Utils.formatSeconds(Long.valueOf(timelimit - seconds)) + ") " + format.format(now), "false");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eYou've ended your editing session in your warp with &6" + Utils.formatSeconds(seconds) + " &eremaining.");
|
||||
Utils.sendMessage(player, "&6&lWarp Create &eStaff will approve your warp once they look at it.");
|
||||
endSb(player);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 1;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// if (timelimit == 20 * 60) {
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = timelimit;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds % 60 == 0) {
|
||||
// Utils.sendMessage(player, "&3" + Utils.formatSeconds(seconds) + " &eleft.");
|
||||
// }
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
// initSB1.setLine(2, ChatColor.DARK_AQUA + "" + formatBoardSec);
|
||||
// if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 3;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// }
|
||||
// if (timelimit == 30 * 60) {
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = timelimit;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds % 60 == 0) {
|
||||
// Utils.sendMessage(player, "&3" + Utils.formatSeconds(seconds) + " &eleft.");
|
||||
// }
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
// initSB1.setLine(2, ChatColor.DARK_AQUA + "" + formatBoardSec);
|
||||
// if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 3;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// }
|
||||
// if (timelimit == 90 * 60) {
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = timelimit;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds % 60 == 0) {
|
||||
// Utils.sendMessage(player, "&3" + Utils.formatSeconds(seconds) + " &eleft.");
|
||||
// }
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
// initSB1.setLine(2, ChatColor.DARK_AQUA + "" + formatBoardSec);
|
||||
// if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 3;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// }
|
||||
// if (timelimit == 40 * 60) {
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = timelimit;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds % 60 == 0) {
|
||||
// Utils.sendMessage(player, "&3" + Utils.formatSeconds(seconds) + " &eleft.");
|
||||
// }
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
// initSB1.setLine(2, ChatColor.DARK_AQUA + "" + formatBoardSec);
|
||||
// if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 3;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// }
|
||||
// if (timelimit == 60 * 60) {
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = timelimit;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds % 60 == 0) {
|
||||
// Utils.sendMessage(player, "&3" + Utils.formatSeconds(seconds) + " &eleft.");
|
||||
// }
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// String formatBoardSec = Utils.formatSeconds(seconds);
|
||||
// initSB1.setLine(2, ChatColor.DARK_AQUA + "" + formatBoardSec);
|
||||
// if (Bukkit.getServer().getPlayer(player.getName()) == null) {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// endSb(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// new BukkitRunnable() {
|
||||
// int seconds = 3;
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (seconds > 0) {
|
||||
// seconds--;
|
||||
// player.setGameMode(GameMode.CREATIVE);
|
||||
// Bukkit.getPlayer(player.getName()).setGameMode(GameMode.CREATIVE);
|
||||
// PlayerWarps.get().reloadConfig();
|
||||
// }
|
||||
// else {
|
||||
// this.cancel();
|
||||
// }
|
||||
// }
|
||||
// }.runTaskTimer(PlayerWarps.get(), 0L, 20L);
|
||||
// }
|
||||
toggleBuild.put(player, true);
|
||||
building.put(player, true);
|
||||
prevent.put(player, true);
|
||||
String UUID = player.getUniqueId().toString();
|
||||
Utils.saveWarpBuilding(UUID);
|
||||
player.setScoreboard(initSB1.getScoreboard());
|
||||
if (notify) {
|
||||
Utils.sendMessage(player, "&eYou're now editing your playerwarp.");
|
||||
Utils.sendConsoleMessage("&6" + player.getName() + " &eis editing their playerwarp!");
|
||||
}
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
// public static void deleteVoidWorld(Player sender, OfflinePlayer player, boolean notify) {
|
||||
// String worldname = "PlayerWarps-World";
|
||||
// World mainworld = Bukkit.getWorld("world");
|
||||
// if (Bukkit.getWorld(worldname) != null) {
|
||||
// if (mainworld != null) {
|
||||
// for (Player players : Bukkit.getWorld(worldname).getPlayers()) {
|
||||
// players.teleport(mainworld.getSpawnLocation());
|
||||
// Utils.sendMessage(players, "&6" + player.getName() + "'s &eplayerwarp has been forcefully deleted.");
|
||||
// }
|
||||
// Bukkit.unloadWorld(worldname, false);
|
||||
// try {
|
||||
// FileUtils.deleteDirectory(new File(worldname));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// String UUID = player.getUniqueId().toString();
|
||||
// Utils.removeWarp(UUID);
|
||||
//
|
||||
// if (notify) {
|
||||
// Utils.sendMessage(sender, "&eYou have forcefully deleted &6" + player.getName() + "'s &eplayerwarp.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (notify) {
|
||||
// Utils.sendMessage(sender, "&6" + player.getName() + "'s &eplayerwarp either doesn't exist or is not loaded.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void approveVoidWorld(Player sender, OfflinePlayer player) {
|
||||
String worldname = "PlayerWarps-World";
|
||||
if (Bukkit.getWorld(worldname) != null) {
|
||||
World w = Bukkit.getWorld(worldname);
|
||||
Location loc;
|
||||
if (Utils.getPlayerWarpLocation(player.getUniqueId().toString()) != null) {
|
||||
loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
sender.teleport(loc);
|
||||
}
|
||||
ready.put(player, true);
|
||||
Utils.sendMessage(sender, "&6" + player.getName() + " &eneeds their playerwarp approved.");
|
||||
Utils.sendMessage(sender, "&f/&ewarpcreate approve &6" + player.getName() + "&e.");
|
||||
Utils.sendMessage(sender, "&eOnce their playerwarp has been checked for blacklisted items and has passed. You can do &f/&ewarpcreate approveconfirm &6" + player.getName() + "&e.");
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static void approveConfirmVoidWorld(OfflinePlayer player, boolean notify) {
|
||||
String worldname = "PlayerWarps-World";
|
||||
if (Bukkit.getWorld(worldname) != null) {
|
||||
World w = Bukkit.getWorld(worldname);
|
||||
Location loc;
|
||||
if (Utils.getPlayerWarpLocation(player.getUniqueId().toString()) != null) {
|
||||
loc = Utils.getPlayerWarpLocation(player.getUniqueId().toString());
|
||||
String UUIDD = player.getUniqueId().toString();
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By") != null || Bukkit.getWorld("PlayerWarps-World") != null) {
|
||||
Utils.saveWarp(UUIDD, loc);
|
||||
BukkitScheduler scheduler = PlayerWarps.get().getServer().getScheduler();
|
||||
scheduler.scheduleSyncRepeatingTask(PlayerWarps.get(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerWarps.get().warpsort.clear();
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Building").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") == null) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
int sort = 0;
|
||||
Location loc = Utils.getPlayerWarpLocation(Bukkit.getOfflinePlayer(uuid).getUniqueId().toString());
|
||||
for (Player players : Bukkit.getWorld("PlayerWarps-World").getPlayers()) {
|
||||
if (Zone.contains(players.getLocation(), loc.getBlockX() + 25, loc.getBlockX() + 20 - 69, -7, 66)) {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
PlayerWarps.get().warpsort.add(sort + " - " + uuid.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(PlayerWarps.get().warpsort, Collections.reverseOrder());
|
||||
if (PlayerWarps.get().getCustomData().getStringList("WarpList") == null) {
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", PlayerWarps.get().warpsort);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else {
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", null);
|
||||
PlayerWarps.get().getCustomData().set("WarpSort", PlayerWarps.get().warpsort);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
}, 20l, (long)(20 * PlayerWarps.get().getCustomData().getLong("guiRefreshRateInSeconds")));
|
||||
}
|
||||
else {
|
||||
Utils.saveWarp(UUIDD, loc);
|
||||
}
|
||||
if (notify) {
|
||||
for (Player players : Bukkit.getOnlinePlayers()) {
|
||||
Utils.sendMessage(players, "&6/PW " + player.getName() + " &eIS NOW &6OPEN&e.");
|
||||
Utils.sendMessage(players, "&6/PW " + player.getName() + " &eIS NOW &6OPEN&e.");
|
||||
Utils.sendMessage(players, "&6/PW " + player.getName() + " &eIS NOW &6OPEN&e.");
|
||||
}
|
||||
}
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void createWarp(Player player) {
|
||||
String worldname = "PlayerWarps-World";
|
||||
if (Bukkit.getWorld(worldname) == null) {
|
||||
WorldCreator wc = new WorldCreator(worldname);
|
||||
|
||||
wc.type(WorldType.FLAT);
|
||||
wc.generatorSettings("2;0;1;");
|
||||
|
||||
wc.createWorld();
|
||||
World w = Bukkit.getWorld(worldname);
|
||||
w.setGameRuleValue("doMobSpawning", "false");
|
||||
w.setGameRuleValue("randomTickSpeed", "0");
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mv import \"" + worldname + "\" normal");
|
||||
if (Bukkit.getWorld(PlayerWarps.get().getCustomData().getString("Main-world")) != null) Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mvm set respawnWorld " + PlayerWarps.get().getCustomData().getString("Main-world") + " \"" + worldname + "\"");
|
||||
Location loc = new Location(w, PlayerWarps.get().nextLocation.getX() + 5000, 0, 0);
|
||||
PlayerWarps.getWarpBox().generateCube(loc, new int[]{49, 58, 49}, new int[]{9, 8, 7}, new int[]{7, 6, 0}, new int[]{47, 11, 47}, new int[]{7, 1, 6}, Material.GLASS, Material.GLOWSTONE, Material.AIR, Material.GRASS, Material.STONE, Material.BEACON);
|
||||
ItemStack block = new ItemStack(Material.GLASS);
|
||||
Utils.saveWallData(player.getUniqueId().toString(), block, true);
|
||||
Utils.saveWallData(player.getUniqueId().toString(), block, false);
|
||||
Location loc3 = loc.clone().add(24.500, 15.00000, -2.500);
|
||||
|
||||
PlayerWarps.get().nextLocation.setX(PlayerWarps.get().nextLocation.getX()+5000);
|
||||
PlayerWarps.get().getCustomData().set("nextXLocation", PlayerWarps.get().nextLocation.getX());
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
Utils.saveWarpCoordsBefore(player.getUniqueId().toString(), loc3);
|
||||
Utils.removeWarpBuilding(player.getUniqueId().toString());
|
||||
}
|
||||
else {
|
||||
if (Utils.getPlayerWarpLocation(player.getUniqueId().toString()) == null) {
|
||||
World w = Bukkit.getWorld(worldname);
|
||||
w.setGameRuleValue("randomTickSpeed", "0");
|
||||
Location loc = new Location(w, PlayerWarps.get().nextLocation.getX() + 5000, 0, 0);
|
||||
PlayerWarps.getWarpBox().generateCube(loc, new int[]{49, 58, 49}, new int[]{9, 8, 7}, new int[]{7, 6, 0}, new int[]{47, 11, 47}, new int[]{7, 1, 6}, Material.GLASS, Material.GLOWSTONE, Material.AIR, Material.GRASS, Material.STONE, Material.BEACON);
|
||||
ItemStack block = new ItemStack(Material.GLASS);
|
||||
Utils.saveWallData(player.getUniqueId().toString(), block, true);
|
||||
Utils.saveWallData(player.getUniqueId().toString(), block, false);
|
||||
Location loc3 = loc.clone().add(24.500, 15.00000, -2.500);
|
||||
PlayerWarps.get().nextLocation.setX(PlayerWarps.get().nextLocation.getX()+5000);
|
||||
PlayerWarps.get().getCustomData().set("nextXLocation", PlayerWarps.get().nextLocation.getX());
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
Utils.saveWarpCoordsBefore(player.getUniqueId().toString(), loc3);
|
||||
Utils.removeWarpBuilding(player.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void endSb(Player player) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
toggleBuild.put(player, false);
|
||||
building.remove(player);
|
||||
Utils.removeWarpBuilding(player.getUniqueId().toString());
|
||||
PlayerWarps.get().reloadConfig();
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
if (PlayerWarps.get().getFeatherboardSupport()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "fb on " + player.getName());
|
||||
}
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
493
src/str/playerwarps/setup/WarpBox.java
Normal file
493
src/str/playerwarps/setup/WarpBox.java
Normal file
@ -0,0 +1,493 @@
|
||||
package str.playerwarps.setup;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import str.playerwarps.*;
|
||||
import str.playerwarps.util.Utils;
|
||||
|
||||
public class WarpBox implements Listener {
|
||||
|
||||
public void generateCube(Location startPos, int[] dimensions, int[] dimensions2, int[] dimensions3, int[] dimensions4, int[] dimensions5, Material cubeMat, Material spawn, Material drop, Material floor, Material spawn2, Material CP) {
|
||||
// startPos is the first block of the cube
|
||||
// the cube will be generated in x+, y+, z+ direction
|
||||
// dimensions need to contain the width, height, length (e.g. {3, 3, 3} -> 3x3x3 Cube)
|
||||
if (dimensions.length == 3) {
|
||||
for (int x = 0; x < dimensions[0]; x++) {
|
||||
for (int y = 0; y < dimensions[1]; y++) {
|
||||
for (int z = 0; z <= dimensions[2]; z++) {
|
||||
Block b = startPos.getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions[0] - 1 || y == dimensions[1] - 1 || z == dimensions[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (dimensions5.length == 3) {
|
||||
// Location loc3 = startPos.clone().add(21, 14, -6);
|
||||
// for (int x = 0; x < dimensions5[0]; x++) {
|
||||
// for (int y = 0; y < dimensions5[1]; y++) {
|
||||
// for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
// Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
// b.setType(spawn2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (dimensions2.length == 3) {
|
||||
Location loc = startPos.clone().add(20, 13, -7);
|
||||
for (int x = 0; x < dimensions2[0]; x++) {
|
||||
for (int y = 0; y < dimensions2[1]; y++) {
|
||||
for (int z = 0; z <= dimensions2[2]; z++) {
|
||||
Block b = loc.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions2[0] - 1 || y == dimensions2[1] - 1 || z == dimensions2[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions3.length == 3) {
|
||||
Location loc3 = startPos.clone().add(21, 14, 0);
|
||||
for (int x = 0; x < dimensions3[0]; x++) {
|
||||
for (int y = 0; y < dimensions3[1]; y++) {
|
||||
for (int z = 0; z <= dimensions3[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions3[0] - 1 || y == dimensions3[1] - 1 || z == dimensions3[2]) {
|
||||
b.setType(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions5.length == 3) {
|
||||
Location loc4 = startPos.clone().add(21, 14, -6);
|
||||
for (int x = 0; x < dimensions5[0]; x++) {
|
||||
for (int y = 0; y < dimensions5[1]; y++) {
|
||||
for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
Block b = loc4.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(spawn2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Location loc2 = startPos.clone().add(24, 14, -3);
|
||||
Block bb = loc2.clone().getBlock();
|
||||
bb.setType(spawn);
|
||||
}
|
||||
}
|
||||
if (dimensions4.length == 3) {
|
||||
Location loc3 = startPos.clone().add(1, 1, 1);
|
||||
for (int x = 0; x < dimensions4[0]; x++) {
|
||||
for (int y = 0; y < dimensions4[1]; y++) {
|
||||
for (int z = 0; z <= dimensions4[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Location loc3 = startPos.clone().add(24, 15, -2).add(0, 1, -5);
|
||||
Block b = loc3.clone().getBlock();
|
||||
b.setType(CP);
|
||||
}
|
||||
|
||||
public String testForWarpWalls(Player player, Block b) {
|
||||
|
||||
Location loc1 = Utils.getPlayerWarpLocation(player.getUniqueId().toString()).subtract(24.500, 15.00000, -2.500);
|
||||
Location loc2 = loc1.clone().add(49, 58, 49);
|
||||
int xLow = Math.min(loc1.getBlockX(), loc2.getBlockX());
|
||||
int xHigh = Math.max(loc1.getBlockX(), loc2.getBlockX());
|
||||
|
||||
int yLow = Math.min(loc1.getBlockY(), loc2.getBlockY());
|
||||
int yHigh = Math.max(loc1.getBlockY(), loc2.getBlockY());
|
||||
|
||||
int zLow = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
int zHigh = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
|
||||
|
||||
Location loc3 = loc1.clone().add(20, 13, -7);
|
||||
Location loc4 = loc3.clone().add(9, 8, 7);
|
||||
int xLow1 = Math.min(loc3.getBlockX(), loc4.getBlockX());
|
||||
int xHigh1 = Math.max(loc3.getBlockX(), loc4.getBlockX());
|
||||
|
||||
int yLow1 = Math.min(loc3.getBlockY(), loc4.getBlockY());
|
||||
int yHigh1 = Math.max(loc3.getBlockY(), loc4.getBlockY());
|
||||
|
||||
int zLow1 = Math.min(loc3.getBlockZ(), loc4.getBlockZ());
|
||||
int zHigh1 = Math.max(loc3.getBlockZ(), loc4.getBlockZ());
|
||||
|
||||
|
||||
|
||||
for (int x = xLow; x <= xHigh; x++) {
|
||||
for (int y = yLow; y <= yHigh; y++) {
|
||||
for (int z = zLow; z <= zHigh; z++) {
|
||||
if (x == xLow || y == yLow || z == zLow || x == xHigh - 1 || y == yHigh - 1 || z == zHigh) {
|
||||
if (b.getX() == x && b.getY() == y && b.getZ() == z) {
|
||||
return "Disallow";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = xLow1; x <= xHigh1; x++) {
|
||||
for (int y = yLow1; y <= yHigh1; y++) {
|
||||
for (int z = zLow1; z <= zHigh1; z++) {
|
||||
if (b.getX() == x && b.getY() == y && b.getZ() == z) {
|
||||
if (b.getType() == Material.BEACON) return "Allow";
|
||||
return "SafeZone";
|
||||
}
|
||||
// if (x == zLow1 || y == zLow1 || z == zLow1 || x == xHigh1 - 1 || y == yHigh1 - 1 || z == zHigh1) {
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
return "Allow";
|
||||
}
|
||||
|
||||
public void generateCubee(Location startPos, int[] dimensions, int[] dimensions2, int[] dimensions3, int[] dimensions4, int[] dimensions5, ItemStack[] cubeMat, Material spawn, Material drop, Material floor, Material spawn2, Material CP) {
|
||||
// startPos is the first block of the cube
|
||||
// the cube will be generated in x+, y+, z+ direction
|
||||
// dimensions need to contain the width, height, length (e.g. {3, 3, 3} -> 3x3x3 Cube)
|
||||
EditSession editSession = new EditSessionBuilder(startPos.getWorld().getName()).fastmode(true).limitUnlimited().build();
|
||||
if (dimensions.length == 3) {
|
||||
for (int x = 0; x < dimensions[0]; x++) {
|
||||
for (int y = 0; y < dimensions[1]; y++) {
|
||||
for (int z = 0; z <= dimensions[2]; z++) {
|
||||
Block b = startPos.getBlock().getRelative(x, y, z);
|
||||
if (b.getType() != Material.BEACON) {
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions[0] - 1 || y == dimensions[1] - 1 || z == dimensions[2]) {
|
||||
if (cubeMat.length == 1) {
|
||||
int random = 0;
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(cubeMat[random].getTypeId(), cubeMat[random].getData().getData()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
int random = ThreadLocalRandom.current().nextInt(0, cubeMat.length);
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(cubeMat[random].getTypeId(), cubeMat[random].getData().getData()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (dimensions5.length == 3) {
|
||||
// Location loc3 = startPos.clone().add(21, 14, -6);
|
||||
// for (int x = 0; x < dimensions5[0]; x++) {
|
||||
// for (int y = 0; y < dimensions5[1]; y++) {
|
||||
// for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
// Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
// b.setType(spawn2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (dimensions2.length == 3) {
|
||||
Location loc = startPos.clone().add(20, 13, -7);
|
||||
for (int x = 0; x < dimensions2[0]; x++) {
|
||||
for (int y = 0; y < dimensions2[1]; y++) {
|
||||
for (int z = 0; z <= dimensions2[2]; z++) {
|
||||
Block b = loc.clone().getBlock().getRelative(x, y, z);
|
||||
if (b.getType() != Material.BEACON) {
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions2[0] - 1 || y == dimensions2[1] - 1 || z == dimensions2[2]) {
|
||||
if (cubeMat.length == 1) {
|
||||
int random = 0;
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(cubeMat[random].getTypeId(), cubeMat[random].getData().getData()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
int random = ThreadLocalRandom.current().nextInt(0, cubeMat.length);
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(cubeMat[random].getTypeId(), cubeMat[random].getData().getData()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions3.length == 3) {
|
||||
Location loc3 = startPos.clone().add(21, 14, 0);
|
||||
for (int x = 0; x < dimensions3[0]; x++) {
|
||||
for (int y = 0; y < dimensions3[1]; y++) {
|
||||
for (int z = 0; z <= dimensions3[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
if (b.getType() != Material.BEACON) {
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions3[0] - 1 || y == dimensions3[1] - 1 || z == dimensions3[2]) {
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(drop.getId()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions5.length == 3) {
|
||||
Location loc4 = startPos.clone().add(21, 14, -6);
|
||||
for (int x = 0; x < dimensions5[0]; x++) {
|
||||
for (int y = 0; y < dimensions5[1]; y++) {
|
||||
for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
Block b = loc4.clone().getBlock().getRelative(x, y, z);
|
||||
if (b.getType() != Material.BEACON) {
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(spawn2.getId()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions4.length == 3) {
|
||||
Location loc3 = startPos.clone().add(1, 1, 1);
|
||||
for (int x = 0; x < dimensions4[0]; x++) {
|
||||
for (int y = 0; y < dimensions4[1]; y++) {
|
||||
for (int z = 0; z <= dimensions4[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(spawn2.getId()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
editSession.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Location loc3 = startPos.clone().add(24, 15, -2).add(0, 1, -5);
|
||||
Block b = loc3.clone().getBlock();
|
||||
try {
|
||||
editSession.setBlock(new Vector(b.getX(), b.getY(), b.getZ()), new BaseBlock(CP.getId()));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Location loc2 = startPos.clone().add(24, 14, -3);
|
||||
Block bb = loc2.clone().getBlock();
|
||||
try {
|
||||
editSession.setBlock(new Vector(bb.getX(), bb.getY(), bb.getZ()), new BaseBlock((spawn.getId())));
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
editSession.flushQueue();
|
||||
}
|
||||
|
||||
public void generateCube1(Location startPos, int[] dimensions, int[] dimensions2, int[] dimensions3, int[] dimensions4, int[] dimensions5, Material cubeMat, Material spawn, Material drop, Material floor, Material spawn2) {
|
||||
// startPos is the first block of the cube
|
||||
// the cube will be generated in x+, y+, z+ direction
|
||||
// dimensions need to contain the width, height, length (e.g. {3, 3, 3} -> 3x3x3 Cube)
|
||||
if (dimensions.length == 3) {
|
||||
for (int x = 0; x < dimensions[0]; x++) {
|
||||
for (int y = 0; y < dimensions[1]; y++) {
|
||||
for (int z = 0; z <= dimensions[2]; z++) {
|
||||
Block b = startPos.getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions[0] - 1 || y == dimensions[1] - 1 || z == dimensions[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (dimensions5.length == 3) {
|
||||
// Location loc3 = startPos.clone().add(21, 14, -6);
|
||||
// for (int x = 0; x < dimensions5[0]; x++) {
|
||||
// for (int y = 0; y < dimensions5[1]; y++) {
|
||||
// for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
// Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
// b.setType(spawn2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (dimensions2.length == 3) {
|
||||
Location loc = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(20, 13, -7);
|
||||
for (int x = 0; x < dimensions2[0]; x++) {
|
||||
for (int y = 0; y < dimensions2[1]; y++) {
|
||||
for (int z = 0; z <= dimensions2[2]; z++) {
|
||||
Block b = loc.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions2[0] - 1 || y == dimensions2[1] - 1 || z == dimensions2[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions3.length == 3) {
|
||||
Location loc3 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(21, 14, 0);
|
||||
for (int x = 0; x < dimensions3[0]; x++) {
|
||||
for (int y = 0; y < dimensions3[1]; y++) {
|
||||
for (int z = 0; z <= dimensions3[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions3[0] - 1 || y == dimensions3[1] - 1 || z == dimensions3[2]) {
|
||||
b.setType(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions5.length == 3) {
|
||||
Location loc4 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(21, 14, -6);
|
||||
for (int x = 0; x < dimensions5[0]; x++) {
|
||||
for (int y = 0; y < dimensions5[1]; y++) {
|
||||
for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
Block b = loc4.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(spawn2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Location loc2 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(24, 14, -3);
|
||||
Block bb = loc2.clone().getBlock();
|
||||
bb.setType(spawn);
|
||||
}
|
||||
}
|
||||
if (dimensions4.length == 3) {
|
||||
Location loc3 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(-19, 1, 1);
|
||||
for (int x = 0; x < dimensions4[0]; x++) {
|
||||
for (int y = 0; y < dimensions4[1]; y++) {
|
||||
for (int z = 0; z <= dimensions4[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateCube2(Location startPos, int[] dimensions, int[] dimensions2, int[] dimensions3, int[] dimensions4, int[] dimensions5, Material cubeMat, Material spawn, Material drop, Material floor, Material spawn2) {
|
||||
// startPos is the first block of the cube
|
||||
// the cube will be generated in x+, y+, z+ direction
|
||||
// dimensions need to contain the width, height, length (e.g. {3, 3, 3} -> 3x3x3 Cube)
|
||||
if (dimensions.length == 3) {
|
||||
for (int x = 0; x < dimensions[0]; x++) {
|
||||
for (int y = 0; y < dimensions[1]; y++) {
|
||||
for (int z = 0; z <= dimensions[2]; z++) {
|
||||
Block b = startPos.getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions[0] - 1 || y == dimensions[1] - 1 || z == dimensions[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (dimensions5.length == 3) {
|
||||
// Location loc3 = startPos.clone().add(21, 14, -6);
|
||||
// for (int x = 0; x < dimensions5[0]; x++) {
|
||||
// for (int y = 0; y < dimensions5[1]; y++) {
|
||||
// for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
// Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
// b.setType(spawn2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (dimensions2.length == 3) {
|
||||
Location loc = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(20, 13, -7);
|
||||
for (int x = 0; x < dimensions2[0]; x++) {
|
||||
for (int y = 0; y < dimensions2[1]; y++) {
|
||||
for (int z = 0; z <= dimensions2[2]; z++) {
|
||||
Block b = loc.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions2[0] - 1 || y == dimensions2[1] - 1 || z == dimensions2[2]) {
|
||||
b.setType(cubeMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions3.length == 3) {
|
||||
Location loc3 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(21, 14, 0);
|
||||
for (int x = 0; x < dimensions3[0]; x++) {
|
||||
for (int y = 0; y < dimensions3[1]; y++) {
|
||||
for (int z = 0; z <= dimensions3[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions3[0] - 1 || y == dimensions3[1] - 1 || z == dimensions3[2]) {
|
||||
b.setType(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dimensions5.length == 3) {
|
||||
Location loc4 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(21, 14, -6);
|
||||
for (int x = 0; x < dimensions5[0]; x++) {
|
||||
for (int y = 0; y < dimensions5[1]; y++) {
|
||||
for (int z = 0; z <= dimensions5[2]; z++) {
|
||||
Block b = loc4.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(spawn2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Location loc2 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(24, 14, -3);
|
||||
Block bb = loc2.clone().getBlock();
|
||||
bb.setType(spawn);
|
||||
}
|
||||
}
|
||||
if (dimensions4.length == 3) {
|
||||
Location loc3 = startPos.clone().getWorld().getBlockAt(0, 0, 0).getLocation().add(-19, 1, 1);
|
||||
for (int x = 0; x < dimensions4[0]; x++) {
|
||||
for (int y = 0; y < dimensions4[1]; y++) {
|
||||
for (int z = 0; z <= dimensions4[2]; z++) {
|
||||
Block b = loc3.clone().getBlock().getRelative(x, y, z);
|
||||
b.setType(floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkPos(Location startPos, int[] dimensions) {
|
||||
if (dimensions.length == 3) {
|
||||
Location loc = startPos.clone().add(23, 3, -8);
|
||||
for (int x = 0; x < dimensions[0]; x++) {
|
||||
for (int y = 0; y < dimensions[1]; y++) {
|
||||
for (int z = 0; z <= dimensions[2]; z++) {
|
||||
if (x == 0 || y == 0 || z == 0 || x == dimensions[0] - 1 || y == dimensions[1] - 1 || z == dimensions[2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
119
src/str/playerwarps/util/ItemMetadata.java
Normal file
119
src/str/playerwarps/util/ItemMetadata.java
Normal file
@ -0,0 +1,119 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.ItemStack;
|
||||
import net.minecraft.server.v1_8_R3.NBTBase;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagByte;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagByteArray;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagDouble;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagEnd;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagFloat;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagInt;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagIntArray;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagList;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagLong;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagShort;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagString;
|
||||
|
||||
public class ItemMetadata {
|
||||
public static org.bukkit.inventory.ItemStack setMetadata(org.bukkit.inventory.ItemStack item, String metadata, Object value){
|
||||
return CraftItemStack.asBukkitCopy(setMetadata(CraftItemStack.asNMSCopy(item), metadata, value));
|
||||
}
|
||||
public static ItemStack setMetadata(ItemStack item, String metadata, Object value){
|
||||
if(item.getTag() == null){
|
||||
item.setTag(new NBTTagCompound());
|
||||
}
|
||||
setTag(item.getTag(), metadata, value);
|
||||
return item;
|
||||
}
|
||||
public static boolean hasMetadata(org.bukkit.inventory.ItemStack item, String metadata){
|
||||
return hasMetadata(CraftItemStack.asNMSCopy(item), metadata);
|
||||
}
|
||||
public static boolean hasMetadata(ItemStack item, String metadata){
|
||||
return item.getTag() == null ? false : item.getTag().hasKey(metadata);
|
||||
}
|
||||
public static Object getMetadata(org.bukkit.inventory.ItemStack item, String metadata){
|
||||
return getMetadata(CraftItemStack.asNMSCopy(item), metadata);
|
||||
}
|
||||
public static Object getMetadata(ItemStack item, String metadata){
|
||||
if(!hasMetadata(item, metadata))return null;
|
||||
return getObject(item.getTag().get(metadata));
|
||||
}
|
||||
private static NBTTagCompound setTag(NBTTagCompound tag, String tagString, Object value) {
|
||||
|
||||
NBTBase base = null;
|
||||
|
||||
if (value instanceof Boolean) {
|
||||
base = new NBTTagByte((byte)(((Boolean)value).booleanValue() ? 1 : 0));
|
||||
} else if (value instanceof Long) {
|
||||
base = new NBTTagLong((Long) value);
|
||||
} else if (value instanceof Integer) {
|
||||
base = new NBTTagInt((Integer) value);
|
||||
} else if (value instanceof Byte) {
|
||||
base = new NBTTagByte((Byte) value);
|
||||
} else if (value instanceof Double) {
|
||||
base = new NBTTagDouble((Double) value);
|
||||
} else if (value instanceof Float) {
|
||||
base = new NBTTagFloat((Float) value);
|
||||
} else if (value instanceof String) {
|
||||
base = new NBTTagString((String) value);
|
||||
} else if (value instanceof Short) {
|
||||
base = new NBTTagShort((Short) value);
|
||||
}
|
||||
|
||||
if(base != null){
|
||||
tag.set(tagString, base);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Object getObject(NBTBase tag){
|
||||
if(tag instanceof NBTTagEnd){
|
||||
return null;
|
||||
}else if(tag instanceof NBTTagLong){
|
||||
return ((NBTTagLong) tag).c();
|
||||
}else if(tag instanceof NBTTagByte){
|
||||
return ((NBTTagByte) tag).f();
|
||||
}else if(tag instanceof NBTTagShort){
|
||||
return ((NBTTagShort) tag).e();
|
||||
}else if(tag instanceof NBTTagInt){
|
||||
return ((NBTTagInt) tag).d();
|
||||
}else if(tag instanceof NBTTagFloat){
|
||||
return ((NBTTagFloat) tag).h();
|
||||
}else if(tag instanceof NBTTagDouble){
|
||||
return ((NBTTagDouble) tag).g();
|
||||
}else if(tag instanceof NBTTagByteArray){
|
||||
return ((NBTTagByteArray) tag).c();
|
||||
}else if(tag instanceof NBTTagString){
|
||||
return ((NBTTagString) tag).a_();
|
||||
}else if(tag instanceof NBTTagList){
|
||||
List<NBTBase> list = null;
|
||||
try {
|
||||
Field field = tag.getClass().getDeclaredField("list");
|
||||
field.setAccessible(true);
|
||||
list = (List<NBTBase>)field.get(tag);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(list == null)return null;
|
||||
List<Object> toReturn = Lists.newArrayList();
|
||||
for(NBTBase base : list){
|
||||
toReturn.add(getObject(base));
|
||||
}
|
||||
return toReturn;
|
||||
}else if(tag instanceof NBTTagCompound){
|
||||
return tag;
|
||||
}else if(tag instanceof NBTTagIntArray){
|
||||
return ((NBTTagIntArray) tag).c();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
31
src/str/playerwarps/util/RandomStringGenerator.java
Normal file
31
src/str/playerwarps/util/RandomStringGenerator.java
Normal file
@ -0,0 +1,31 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Anand
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RandomStringGenerator {
|
||||
public static String randomString(int length, boolean numeric,
|
||||
boolean alphabetical, boolean symbolic) {
|
||||
if (!numeric && !alphabetical && !symbolic) {
|
||||
alphabetical = true;
|
||||
numeric = true;
|
||||
}
|
||||
String characters = (alphabetical ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "")
|
||||
+ (numeric ? "0123456789" : "")
|
||||
+ (symbolic ? "~,.:?;[]{}`^!@#$%&*()-_+=></ " : "");
|
||||
Random random = new Random();
|
||||
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = characters.charAt(random.nextInt(characters.length()));
|
||||
if (random.nextInt(2) == 0 && Character.isUpperCase(c)) {
|
||||
c = Character.toLowerCase(c);
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
102
src/str/playerwarps/util/ScoreboardWrapper.java
Normal file
102
src/str/playerwarps/util/ScoreboardWrapper.java
Normal file
@ -0,0 +1,102 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
/**
|
||||
* ScoreboardWrapper is a class that wraps Bukkit Scoreboard API
|
||||
* and makes your life easier.
|
||||
*/
|
||||
public class ScoreboardWrapper {
|
||||
|
||||
public static final int MAX_LINES = 16;
|
||||
|
||||
private final Scoreboard scoreboard;
|
||||
private final Objective objective;
|
||||
|
||||
private final List<String> modifies = new ArrayList<>(MAX_LINES);
|
||||
|
||||
/**
|
||||
* Instantiates a new ScoreboardWrapper with a default title.
|
||||
*/
|
||||
public ScoreboardWrapper(String title) {
|
||||
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
objective = scoreboard.registerNewObjective(title, "dummy");
|
||||
objective.setDisplayName(title);
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scoreboard title.
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
objective.setDisplayName(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the line with §r strings in the way to add
|
||||
* a line equal to another.
|
||||
*/
|
||||
private String getLineCoded(String line) {
|
||||
String result = line;
|
||||
while (modifies.contains(result))
|
||||
result += ChatColor.RESET;
|
||||
return result.substring(0, Math.min(40, result.length()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new line to the scoreboard. Throw an error if the lines count are higher than 16.
|
||||
*/
|
||||
public void addLine(String line) {
|
||||
if (modifies.size() > MAX_LINES)
|
||||
throw new IndexOutOfBoundsException("You cannot add more than 16 lines.");
|
||||
String modified = getLineCoded(line);
|
||||
modifies.add(modified);
|
||||
objective.getScore(modified).setScore(-(modifies.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a blank space to the scoreboard.
|
||||
*/
|
||||
public void addBlankSpace() {
|
||||
addLine(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a scoreboard line to an exact index (between 0 and 15).
|
||||
*/
|
||||
public void setLine(int index, String line) {
|
||||
if (index < 0 || index >= MAX_LINES)
|
||||
throw new IndexOutOfBoundsException("The index cannot be negative or higher than 15.");
|
||||
String oldModified = modifies.get(index);
|
||||
scoreboard.resetScores(oldModified);
|
||||
String modified = getLineCoded(line);
|
||||
modifies.set(index, modified);
|
||||
objective.getScore(modified).setScore(-(index + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Bukkit Scoreboard.
|
||||
*/
|
||||
public Scoreboard getScoreboard() {
|
||||
return scoreboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for debug.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
int i = 0;
|
||||
for (String string : modifies)
|
||||
out += -(i + 1) + ")-> " + string + ";\n";
|
||||
return out;
|
||||
}
|
||||
}
|
285
src/str/playerwarps/util/TaskChain.java
Normal file
285
src/str/playerwarps/util/TaskChain.java
Normal file
@ -0,0 +1,285 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import str.playerwarps.PlayerWarps;
|
||||
|
||||
/**
|
||||
* Facilitates Control Flow for the Bukkit Scheduler to easily jump between
|
||||
* Async and Sync tasks without deeply nested callbacks, passing the response of the
|
||||
* previous task to the next task to use.
|
||||
*
|
||||
* Usage example: TaskChain.newChain()
|
||||
* .add(new TaskChain.AsyncTask {})
|
||||
* .add(new TaskChain.Task {})
|
||||
* .add(new AsyncTask {})
|
||||
* .execute();
|
||||
*/
|
||||
public class TaskChain {
|
||||
/**
|
||||
* Utility helpers for Task returns. Changes the behavior of the Chain when these are returned.
|
||||
*/
|
||||
// Tells a task it will perform call back later.
|
||||
public static final Object ASYNC = new Object();
|
||||
// Abort executing the chain
|
||||
public static final Object ABORT = new Object();
|
||||
|
||||
|
||||
/**
|
||||
* =============================================================================================
|
||||
*/
|
||||
ConcurrentLinkedQueue<BaseTask> chainQueue = new ConcurrentLinkedQueue<BaseTask>();
|
||||
|
||||
boolean executed = false;
|
||||
Object previous = null;
|
||||
boolean async;
|
||||
private final Plugin plugin;
|
||||
public TaskChain() {
|
||||
this.plugin = PlayerWarps.get(); // TODO: Change to get an instance to your plugin!
|
||||
this.async = !Bukkit.isPrimaryThread();
|
||||
}
|
||||
/**
|
||||
* =============================================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts a new chain.
|
||||
* @return
|
||||
*/
|
||||
public static TaskChain newChain() {
|
||||
return new TaskChain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a delay to the chain execution
|
||||
* @param ticks # of ticks to delay before next task (20 = 1 second)
|
||||
* @return
|
||||
*/
|
||||
public TaskChain delay(final int ticks) {
|
||||
add(new GenericTask() {
|
||||
{
|
||||
// Prevent switching between sync/async
|
||||
final BaseTask peek = TaskChain.this.chainQueue.peek();
|
||||
this.async = peek != null ? peek.async : TaskChain.this.async;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
final GenericTask task = this;
|
||||
task.chain.async = false;
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.next();
|
||||
}
|
||||
}, ticks);
|
||||
async();
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a step to the chain execution. Async*Task will run off of main thread,
|
||||
* *Task will run sync with main thread
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
public TaskChain add(BaseTask task) {
|
||||
synchronized (this) {
|
||||
if (executed) {
|
||||
throw new RuntimeException("TaskChain is executing");
|
||||
}
|
||||
}
|
||||
|
||||
chainQueue.add(task);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finished adding tasks, begins executing them.
|
||||
*/
|
||||
public void execute() {
|
||||
synchronized (this) {
|
||||
if (executed) {
|
||||
throw new RuntimeException("Already executed");
|
||||
}
|
||||
executed = true;
|
||||
}
|
||||
nextTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires off the next task, and switches between Async/Sync as necessary.
|
||||
*/
|
||||
private void nextTask() {
|
||||
final TaskChain chain = this;
|
||||
final BaseTask task = chainQueue.poll();
|
||||
if (task == null) {
|
||||
// done!
|
||||
return;
|
||||
}
|
||||
if (task.async) {
|
||||
if (async) {
|
||||
task.run(this);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chain.async = true;
|
||||
task.run(chain);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (async) {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chain.async = false;
|
||||
task.run(chain);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
task.run(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides foundation of a task with what the previous task type should return
|
||||
* to pass to this and what this task will return.
|
||||
* @param <R> Return Type
|
||||
* @param <A> Argument Type Expected
|
||||
*/
|
||||
private abstract static class BaseTask<R, A> {
|
||||
TaskChain chain = null;
|
||||
boolean async = false;
|
||||
boolean executed = false;
|
||||
|
||||
/**
|
||||
* Task Type classes will implement this
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
protected abstract R runTask(A arg);
|
||||
|
||||
/**
|
||||
* Called internally by Task Chain to facilitate executing the task and then the next task.
|
||||
* @param chain
|
||||
*/
|
||||
private void run(TaskChain chain) {
|
||||
final Object arg = chain.previous;
|
||||
chain.previous = null;
|
||||
this.chain = chain;
|
||||
R ret = this.runTask((A) arg);
|
||||
if (chain.previous == null) {
|
||||
chain.previous = ret;
|
||||
}
|
||||
if (chain.previous != ASYNC && chain.previous != ABORT) {
|
||||
synchronized (this) {
|
||||
executed = true;
|
||||
}
|
||||
chain.nextTask();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the TaskChain to abort processing any more tasks.
|
||||
*/
|
||||
public R abort() {
|
||||
chain.previous = ABORT;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the TaskChain you will manually invoke the next task manually using task.next(response);
|
||||
*/
|
||||
public R async() {
|
||||
chain.previous = ASYNC;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only to be used when paired with return this.async(); Must be called to execute the next task.
|
||||
*
|
||||
* To be used inside a callback of another operation that is performed async.
|
||||
* @param resp
|
||||
*/
|
||||
public void next(R resp) {
|
||||
synchronized (this) {
|
||||
if (executed) {
|
||||
throw new RuntimeException(
|
||||
"This task has already been executed. return this.async()");
|
||||
}
|
||||
}
|
||||
chain.async = !Bukkit.isPrimaryThread(); // We don't know where the task called this from.
|
||||
chain.previous = resp;
|
||||
chain.nextTask();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General abstract classes to be used for various tasks in the chain.
|
||||
*
|
||||
* First Tasks are for when you do not have or do not care about the return
|
||||
* value of a previous task.
|
||||
*
|
||||
* Last Tasks are for when you do not need to use a return type.
|
||||
*
|
||||
* A Generic task simply does not care about Previous Return or return
|
||||
* anything itself.
|
||||
*
|
||||
* Async Tasks will not run on the Minecraft Thread and should not use the
|
||||
* Bukkit API unless it is thread safe.
|
||||
*/
|
||||
public abstract static class Task<R, A> extends BaseTask<R, A> {
|
||||
protected abstract R run(A arg);
|
||||
|
||||
@Override
|
||||
protected R runTask(A arg) {
|
||||
return run(arg);
|
||||
}
|
||||
}
|
||||
public abstract static class GenericTask extends BaseTask<Object, Object> {
|
||||
protected abstract void run();
|
||||
@Override
|
||||
protected Object runTask(Object arg) {
|
||||
run();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void next() {
|
||||
next(null);
|
||||
}
|
||||
}
|
||||
public abstract static class FirstTask<R> extends BaseTask<R, Object> {
|
||||
protected abstract R run();
|
||||
|
||||
@Override
|
||||
protected R runTask(Object arg) {
|
||||
return run();
|
||||
}
|
||||
}
|
||||
public abstract static class LastTask<A> extends BaseTask<Object, A> {
|
||||
protected abstract void run(A arg);
|
||||
|
||||
@Override
|
||||
protected Object runTask(A arg) {
|
||||
run(arg);
|
||||
return null;
|
||||
}
|
||||
public void next() {
|
||||
next(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Async helpers
|
||||
public abstract static class AsyncTask<R, A> extends Task<R, A> {{async = true;}}
|
||||
public abstract static class AsyncGenericTask extends GenericTask {{async = true;}}
|
||||
public abstract static class AsyncFirstTask<R> extends FirstTask<R> {{async = true;}}
|
||||
public abstract static class AsyncLastTask<A> extends LastTask<A> {{async = true;}}
|
||||
}
|
18
src/str/playerwarps/util/TitleUpdater_1_8_R3.java
Normal file
18
src/str/playerwarps/util/TitleUpdater_1_8_R3.java
Normal file
@ -0,0 +1,18 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.ChatMessage;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
|
||||
|
||||
public class TitleUpdater_1_8_R3 {
|
||||
|
||||
public static void update(Player p, String title) {
|
||||
EntityPlayer ep = ((CraftPlayer)p).getHandle();
|
||||
PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(ep.activeContainer.windowId, "minecraft:chest", new ChatMessage(title), p.getOpenInventory().getTopInventory().getSize());
|
||||
ep.playerConnection.sendPacket(packet);
|
||||
ep.updateInventory(ep.activeContainer);
|
||||
}
|
||||
}
|
443
src/str/playerwarps/util/Utils.java
Normal file
443
src/str/playerwarps/util/Utils.java
Normal file
@ -0,0 +1,443 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import str.playerwarps.PlayerWarps;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static String formatSeconds(long seconds)
|
||||
{
|
||||
long days = seconds / (24 * 60 * 60);
|
||||
seconds %= 24 * 60 * 60;
|
||||
long hh = seconds / (60 * 60);
|
||||
seconds %= 60 * 60;
|
||||
long mm = seconds / 60;
|
||||
seconds %= 60;
|
||||
long ss = seconds;
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
return days + "d" + hh + "h" + mm + "m" + ss + "s";
|
||||
}
|
||||
if (hh > 0)
|
||||
{
|
||||
return hh + "h" + mm + "m" + ss + "s";
|
||||
}
|
||||
if (mm > 0)
|
||||
{
|
||||
return mm + "m" + ss + "s";
|
||||
}
|
||||
return ss + "s";
|
||||
}
|
||||
|
||||
public static String replace(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
sender.sendMessage(replace(message));
|
||||
}
|
||||
|
||||
public static void bMsg(String message) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) { sendMessage(p, message); }
|
||||
}
|
||||
|
||||
public static void sendConsoleMessage(String message) {
|
||||
PlayerWarps.get().getServer().getConsoleSender().sendMessage(replace(message));
|
||||
}
|
||||
|
||||
public static void saveUsedWarpCreate(String str) {
|
||||
PlayerWarps.get().getCustomData().set("Used-Warp-Blocks." + str, true);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static boolean getUsedWarpCreate(String str) {
|
||||
boolean duped = false;
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Used-Warp-Blocks") != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Used-Warp-Blocks." + str) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Used-Warp-Blocks." + str).equalsIgnoreCase("true")) {
|
||||
duped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return duped;
|
||||
}
|
||||
|
||||
public static void saveWarpCoordsBefore(String playeruuid, Location loc) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".xb", loc.getX());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".yb", loc.getY());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".zb", loc.getZ());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".worldnameB", loc.getWorld().getName());
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static int getEditTime(String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warp-Edit-Time") != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Time." + playeruuid) != null) {
|
||||
return PlayerWarps.get().getCustomData().getInt("Warp-Edit-Time." + playeruuid);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean getTransactions(String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warp-Edit-Transactions") != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Transactions." + playeruuid) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void deleteWarpTransactions(String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warp-Edit-Transactions") != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Transactions." + playeruuid) != null) {
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Transactions." + playeruuid, null);
|
||||
}
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warp-Edit-Time") != null) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Time." + playeruuid) != null) {
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Time." + playeruuid, null);
|
||||
}
|
||||
}
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid, null);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static void saveEditTime(String playeruuid, int time, String transaction, String adding) {
|
||||
List<String> transactions = new ArrayList<String>();
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Transactions." + playeruuid) == null) {
|
||||
transactions.add((adding.equalsIgnoreCase("true") ? "&a" : "&c") + transaction);
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Transactions." + playeruuid, transactions);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + playeruuid).size() < 10) {
|
||||
int count = 1;
|
||||
List<String> t = (List<String>) PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + playeruuid);
|
||||
// if (t.size() == 1) {
|
||||
// t.get(0).replace("&e&l1", "&e&l2");
|
||||
// }
|
||||
transactions.add((adding.equalsIgnoreCase("true") ? "&a" : "&c") + transaction);
|
||||
for (int i = 0; i < t.size(); i++) {
|
||||
transactions.add(t.get(i));
|
||||
}
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Transactions." + playeruuid, transactions);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
else if (PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + playeruuid).size() == 10) {
|
||||
int count = 1;
|
||||
List<String> t = (List<String>) PlayerWarps.get().getCustomData().getStringList("Warp-Edit-Transactions." + playeruuid);
|
||||
t.remove(9);
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Transactions", t);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
transactions.add((adding.equalsIgnoreCase("true") ? "&a" : "&c") + transaction);
|
||||
for (int i = 0; i < t.size(); i++) {
|
||||
transactions.add(t.get(i));
|
||||
}
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Transactions." + playeruuid, transactions);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
if (PlayerWarps.get().getCustomData().get("Warp-Edit-Time." + playeruuid) == null) {
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Time." + playeruuid, time);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (adding.equalsIgnoreCase("true")) {
|
||||
time = PlayerWarps.get().getCustomData().getInt("Warp-Edit-Time." + playeruuid) + time;
|
||||
}
|
||||
PlayerWarps.get().getCustomData().set("Warp-Edit-Time." + playeruuid, time);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void saveWarpBuilding(String playeruuid) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Building", true);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static void removeWarpBuilding(String playeruuid) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Building", false);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Approved", false);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Need-Approval", true);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
|
||||
public static void saveWarp(String playeruuid, Location loc) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".x", loc.getX());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".y", loc.getY());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".z", loc.getZ());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".worldname", loc.getWorld().getName());
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Need-Approval", false);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static void removeWarp(String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid, null);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getWallData(String playeruuid, boolean first) {
|
||||
if (!PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) return null;
|
||||
if (first) {
|
||||
ItemStack compare = PlayerWarps.get().getCustomData().getItemStack("Warps-Created-By." + playeruuid + ".roomWallItem");
|
||||
return compare;
|
||||
}
|
||||
else {
|
||||
ItemStack compare = PlayerWarps.get().getCustomData().getItemStack("Warps-Created-By." + playeruuid + ".warpWallItem");
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveWallData(String playeruuid, ItemStack block, boolean first) {
|
||||
if (first) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".roomWallItem", block);
|
||||
}
|
||||
else {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".warpWallItem", block);
|
||||
}
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static void fixWarp(String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) {
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".x", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".y", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".z", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".worldname", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Building", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Approved", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Need-Approval", null);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveEditingWarp(String playeruuid) {
|
||||
if (!PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) return;
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".x", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".y", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".z", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".worldname", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Building", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Approved", null);
|
||||
PlayerWarps.get().getCustomData().set("Warps-Created-By." + playeruuid + ".Need-Approval", null);
|
||||
PlayerWarps.get().saveConfig();
|
||||
PlayerWarps.get().reloadConfig();
|
||||
}
|
||||
|
||||
public static void teleportToWarp(Player player, String playeruuid) {
|
||||
if (PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) {
|
||||
double x = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".x");
|
||||
double y = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".y");
|
||||
double z = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".z");
|
||||
String worldname = PlayerWarps.get().getCustomData().getString("Warps-Created-By." + playeruuid + ".worldname");
|
||||
Location loc = new Location(Bukkit.getWorld(worldname), x, y, z);
|
||||
player.teleport(loc);
|
||||
if (Bukkit.getPlayer(UUID.fromString(playeruuid)) != null) {
|
||||
Utils.sendMessage(player, "&eTeleporting to &6" + Bukkit.getPlayer(UUID.fromString(playeruuid)).getName() + "'s &eplayerwarp.");
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(player, "&eTeleporting to &6" + Bukkit.getOfflinePlayer(UUID.fromString(playeruuid)).getName() + "'s &eplayerwarp.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getPlayerWarpLocation(String playeruuid) {
|
||||
if (!PlayerWarps.get().getCustomData().contains("Warps-Created-By." + playeruuid)) return null;
|
||||
double x = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".xb");
|
||||
double y = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".yb");
|
||||
double z = PlayerWarps.get().getCustomData().getDouble("Warps-Created-By." + playeruuid + ".zb");
|
||||
String worldname = PlayerWarps.get().getCustomData().getString("Warps-Created-By." + playeruuid + ".worldnameb");
|
||||
Location loc = new Location(Bukkit.getWorld("PlayerWarps-World"), x, y, z);
|
||||
return loc;
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(UUID uuid) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
return offlinePlayer.hasPlayedBefore() ? offlinePlayer : null;
|
||||
}
|
||||
|
||||
public static int getWarps() {
|
||||
int i = 0;
|
||||
Set<String> set = PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By").getKeys(false);
|
||||
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
|
||||
UUID uuid = UUID.fromString(it.next());
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval") != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + uuid.toString() + ".Need-Approval").equalsIgnoreCase("false")) {
|
||||
if (PlayerWarps.get().getCustomData().get("Warps-Created-By." + uuid.toString() + ".worldname") != null) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static String replace1(String message) {
|
||||
return message.replaceAll("&", "\u00A7");
|
||||
}
|
||||
|
||||
public static boolean isPlayerBuilding(Player playeruuid) {
|
||||
if (playeruuid.getWorld() == Bukkit.getWorld("PlayerWarp " + playeruuid.getUniqueId().toString())) {
|
||||
if (PlayerWarps.get().getCustomData().getConfigurationSection("Warps-Created-By." + playeruuid.getUniqueId().toString()) != null) {
|
||||
if (PlayerWarps.get().getCustomData().getString("Warps-Created-By." + playeruuid.getUniqueId().toString() + ".Building").equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the HELP as a paginated list of strings in chat to a player
|
||||
*
|
||||
* @param sender The sender to send the list to
|
||||
* @param list The list to paginate
|
||||
* @param page The page number to display.
|
||||
*/
|
||||
public static void paginate(CommandSender sender, ArrayList<String> list, int page) {
|
||||
int contentLinesPerPage = 5;
|
||||
int totalPageCount = 1;
|
||||
|
||||
if((list.size() % contentLinesPerPage) == 0) {
|
||||
if(list.size() > 0) {
|
||||
totalPageCount = list.size() / contentLinesPerPage;
|
||||
}
|
||||
}
|
||||
else {
|
||||
totalPageCount = (list.size() / contentLinesPerPage) + 1;
|
||||
}
|
||||
if(page <= totalPageCount) {
|
||||
String paginatefirstline = "&ePage &3" + String.valueOf(page) + "&f/&3" + String.valueOf(totalPageCount) + "&e.";
|
||||
|
||||
Utils.sendMessage(sender, paginatefirstline);
|
||||
//beginline
|
||||
|
||||
if(list.isEmpty()) {
|
||||
Utils.sendMessage(sender, "&cThere is nothing to show...");
|
||||
}
|
||||
else {
|
||||
int i = 0, k = 0;
|
||||
page--;
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
for (String entry : list) {
|
||||
k++;
|
||||
if ((((page * contentLinesPerPage) + i + 1) == k) && (k != ((page * contentLinesPerPage) + contentLinesPerPage + 1))) {
|
||||
i++;
|
||||
TextComponent msg = new TextComponent(Utils.replace(" - &3" + entry + " &f- &eClick to view and approve warp."));
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Utils.replace("&eClick to view and approve warp.")).create()));
|
||||
msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warpcreate approve " + entry));
|
||||
player.spigot().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
//endline
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eThere are only &3" + totalPageCount + " &epage(s).");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the HELP as a paginated list of strings in chat to a player
|
||||
*
|
||||
* @param sender The sender to send the list to
|
||||
* @param list The list to paginate
|
||||
* @param page The page number to display.
|
||||
*/
|
||||
public static void paginate1(CommandSender sender, ArrayList<String> list, int page) {
|
||||
int contentLinesPerPage = 5;
|
||||
int totalPageCount = 1;
|
||||
|
||||
if((list.size() % contentLinesPerPage) == 0) {
|
||||
if(list.size() > 0) {
|
||||
totalPageCount = list.size() / contentLinesPerPage;
|
||||
}
|
||||
}
|
||||
else {
|
||||
totalPageCount = (list.size() / contentLinesPerPage) + 1;
|
||||
}
|
||||
if(page <= totalPageCount) {
|
||||
String paginatefirstline = "&ePage &3" + String.valueOf(page) + "&f/&3" + String.valueOf(totalPageCount) + "&e.";
|
||||
|
||||
Utils.sendMessage(sender, paginatefirstline);
|
||||
//beginline
|
||||
|
||||
if(list.isEmpty()) {
|
||||
Utils.sendMessage(sender, "&cThere is nothing to show...");
|
||||
}
|
||||
else {
|
||||
int i = 0, k = 0;
|
||||
page--;
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
for (String entry : list) {
|
||||
k++;
|
||||
if ((((page * contentLinesPerPage) + i + 1) == k) && (k != ((page * contentLinesPerPage) + contentLinesPerPage + 1))) {
|
||||
i++;
|
||||
TextComponent msg = new TextComponent(Utils.replace(" &e- &6" + entry));
|
||||
player.spigot().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
//endline
|
||||
}
|
||||
else {
|
||||
Utils.sendMessage(sender, "&eThere are only &3" + totalPageCount + " &epage(s).");
|
||||
}
|
||||
}
|
||||
|
||||
public static void performCommand(Player player, String command) {
|
||||
TaskChain.newChain().add(new TaskChain.GenericTask() {
|
||||
public void run() {
|
||||
player.chat("/" + command);
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
}
|
18
src/str/playerwarps/util/Zone.java
Normal file
18
src/str/playerwarps/util/Zone.java
Normal file
@ -0,0 +1,18 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Zone {
|
||||
|
||||
|
||||
|
||||
public static boolean contains(Location loc, int x1, int x2, int z1, int z2) {
|
||||
|
||||
ZoneVector curr = new ZoneVector(loc.getBlockX(), loc.getBlockZ());
|
||||
ZoneVector min = new ZoneVector(Math.min(x1, x2), Math.min(z1, z2));
|
||||
ZoneVector max = new ZoneVector(Math.max(x1, x2), Math.max(z1, z2));
|
||||
|
||||
return curr.isInAABB(min, max);
|
||||
}
|
||||
|
||||
}
|
19
src/str/playerwarps/util/ZoneVector.java
Normal file
19
src/str/playerwarps/util/ZoneVector.java
Normal file
@ -0,0 +1,19 @@
|
||||
package str.playerwarps.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ZoneVector{
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public ZoneVector(int x, int z){
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public boolean isInAABB(ZoneVector min, ZoneVector max) {
|
||||
return ((this.x <= max.x) && (this.x >=min.x) && (this.z <= max.z) && (this.z >= min.z));
|
||||
|
||||
//Getter and setters for x y z
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user