2015-08-31 11:36:24 +02:00
|
|
|
|
/*
|
2020-06-14 14:29:18 +02:00
|
|
|
|
* Copyright or © or Copr. Moribus (2013)
|
|
|
|
|
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
|
2021-04-11 23:48:16 +02:00
|
|
|
|
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 – 2021)
|
|
|
|
|
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 – 2021)
|
2015-08-31 11:36:24 +02:00
|
|
|
|
*
|
2020-06-14 14:29:18 +02:00
|
|
|
|
* This software is a computer program whose purpose is to allow insertion of
|
|
|
|
|
* custom images in a Minecraft world.
|
2015-08-31 11:36:24 +02:00
|
|
|
|
*
|
2021-04-11 23:48:16 +02:00
|
|
|
|
* This software is governed by the CeCILL license under French law and
|
2020-06-14 14:29:18 +02:00
|
|
|
|
* abiding by the rules of distribution of free software. You can use,
|
2021-04-11 23:48:16 +02:00
|
|
|
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
2020-06-14 14:29:18 +02:00
|
|
|
|
* license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
|
|
* "http://www.cecill.info".
|
2015-08-31 11:36:24 +02:00
|
|
|
|
*
|
2020-06-14 14:29:18 +02:00
|
|
|
|
* As a counterpart to the access to the source code and rights to copy,
|
|
|
|
|
* modify and redistribute granted by the license, users are provided only
|
|
|
|
|
* with a limited warranty and the software's author, the holder of the
|
|
|
|
|
* economic rights, and the successive licensors have only limited
|
|
|
|
|
* liability.
|
|
|
|
|
*
|
|
|
|
|
* In this respect, the user's attention is drawn to the risks associated
|
|
|
|
|
* with loading, using, modifying and/or developing or reproducing the
|
|
|
|
|
* software by the user in light of its specific status of free software,
|
|
|
|
|
* that may mean that it is complicated to manipulate, and that also
|
|
|
|
|
* therefore means that it is reserved for developers and experienced
|
|
|
|
|
* professionals having in-depth computer knowledge. Users are therefore
|
|
|
|
|
* encouraged to load and test the software's suitability as regards their
|
|
|
|
|
* requirements in conditions enabling the security of their systems and/or
|
|
|
|
|
* data to be ensured and, more generally, to use and operate it in the
|
|
|
|
|
* same conditions as regards security.
|
|
|
|
|
*
|
|
|
|
|
* The fact that you are presently reading this means that you have had
|
2021-04-11 23:48:16 +02:00
|
|
|
|
* knowledge of the CeCILL license and that you accept its terms.
|
2015-08-31 11:36:24 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2015-12-29 19:12:36 +01:00
|
|
|
|
package fr.moribus.imageonmap.gui;
|
|
|
|
|
|
2018-01-24 00:16:58 +01:00
|
|
|
|
import fr.moribus.imageonmap.Permissions;
|
2015-12-29 19:12:36 +01:00
|
|
|
|
import fr.moribus.imageonmap.map.ImageMap;
|
|
|
|
|
import fr.moribus.imageonmap.map.PosterMap;
|
|
|
|
|
import fr.moribus.imageonmap.map.SingleMap;
|
2016-04-02 00:43:09 +02:00
|
|
|
|
import fr.moribus.imageonmap.ui.MapItemManager;
|
2020-11-15 19:33:16 +01:00
|
|
|
|
import fr.zcraft.quartzlib.components.gui.ExplorerGui;
|
|
|
|
|
import fr.zcraft.quartzlib.components.gui.Gui;
|
|
|
|
|
import fr.zcraft.quartzlib.components.gui.GuiAction;
|
|
|
|
|
import fr.zcraft.quartzlib.components.gui.PromptGui;
|
|
|
|
|
import fr.zcraft.quartzlib.components.i18n.I;
|
2021-09-03 00:26:27 +02:00
|
|
|
|
import fr.zcraft.quartzlib.tools.PluginLogger;
|
2020-11-15 19:33:16 +01:00
|
|
|
|
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
|
2020-12-27 02:24:47 +01:00
|
|
|
|
import fr.zcraft.quartzlib.tools.runners.RunTask;
|
2016-07-07 02:04:13 +02:00
|
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
2015-12-29 19:12:36 +01:00
|
|
|
|
import org.bukkit.Material;
|
2020-08-27 01:32:04 +02:00
|
|
|
|
import org.bukkit.OfflinePlayer;
|
2015-12-29 19:12:36 +01:00
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2015-09-10 15:27:09 +02:00
|
|
|
|
|
2015-08-31 11:36:24 +02:00
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
public class MapDetailGui extends ExplorerGui<Integer> {
|
2015-09-10 18:17:35 +02:00
|
|
|
|
private final ImageMap map;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
private OfflinePlayer offplayer;
|
2020-08-27 01:32:04 +02:00
|
|
|
|
private String name;
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
public MapDetailGui(ImageMap map, OfflinePlayer p, String name) {
|
2020-12-26 22:51:44 +01:00
|
|
|
|
super();
|
2020-12-10 22:13:05 +01:00
|
|
|
|
this.map = map;
|
|
|
|
|
this.offplayer = p;
|
|
|
|
|
this.name = name;
|
2015-08-31 11:36:24 +02:00
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
2015-08-31 11:36:24 +02:00
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected ItemStack getViewItem(int x, int y) {
|
2019-10-26 14:26:12 +02:00
|
|
|
|
final Material partMaterial = y % 2 == x % 2 ? Material.MAP : Material.PAPER;
|
2016-05-21 18:55:32 +02:00
|
|
|
|
|
2018-01-24 00:16:58 +01:00
|
|
|
|
final ItemStackBuilder builder = new ItemStackBuilder(partMaterial)
|
2016-07-08 04:45:08 +02:00
|
|
|
|
.title(I.t(getPlayerLocale(), "{green}Map part"))
|
2016-07-10 17:16:04 +02:00
|
|
|
|
.lore(I.t(getPlayerLocale(), "{gray}Row: {white}{0}", y + 1))
|
2018-01-24 00:16:58 +01:00
|
|
|
|
.lore(I.t(getPlayerLocale(), "{gray}Column: {white}{0}", x + 1));
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (Permissions.GET.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
builder.loreLine().lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part"));
|
2020-12-10 22:13:05 +01:00
|
|
|
|
}
|
2018-01-24 00:16:58 +01:00
|
|
|
|
|
|
|
|
|
return builder.item();
|
2015-09-10 18:17:35 +02:00
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
2016-07-07 02:04:13 +02:00
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected ItemStack getViewItem(Integer mapId) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
final int index = ((PosterMap) map).getIndex(mapId);
|
2019-10-26 14:26:12 +02:00
|
|
|
|
final Material partMaterial = index % 2 == 0 ? Material.MAP : Material.PAPER;
|
2016-07-07 02:04:13 +02:00
|
|
|
|
|
2018-01-24 00:16:58 +01:00
|
|
|
|
final ItemStackBuilder builder = new ItemStackBuilder(partMaterial)
|
2016-07-08 04:45:08 +02:00
|
|
|
|
.title(I.t(getPlayerLocale(), "{green}Map part"))
|
2018-01-24 00:16:58 +01:00
|
|
|
|
.lore(I.t(getPlayerLocale(), "{gray}Part: {white}{0}", index + 1));
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (Permissions.GET.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
builder.loreLine().lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part"));
|
2020-12-10 22:13:05 +01:00
|
|
|
|
}
|
2018-01-24 00:16:58 +01:00
|
|
|
|
|
|
|
|
|
return builder.item();
|
2015-09-10 18:17:35 +02:00
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
2016-04-02 00:43:09 +02:00
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected ItemStack getPickedUpItem(int x, int y) {
|
|
|
|
|
if (!Permissions.GET.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
return null;
|
2016-04-02 00:43:09 +02:00
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
|
|
|
|
if (map instanceof SingleMap) {
|
|
|
|
|
return MapItemManager.createMapItem((SingleMap) map, true);
|
|
|
|
|
} else if (map instanceof PosterMap) {
|
|
|
|
|
return MapItemManager.createMapItem((PosterMap) map, x, y);
|
2016-04-02 00:43:09 +02:00
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
2016-05-21 18:55:32 +02:00
|
|
|
|
throw new IllegalStateException("Unsupported map type: " + map.getType());
|
2016-04-02 00:43:09 +02:00
|
|
|
|
}
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2016-07-07 02:04:13 +02:00
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected ItemStack getPickedUpItem(Integer mapId) {
|
|
|
|
|
if (!Permissions.GET.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
return null;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
}
|
2018-01-24 00:16:58 +01:00
|
|
|
|
|
|
|
|
|
final PosterMap poster = (PosterMap) map;
|
2016-07-07 02:04:13 +02:00
|
|
|
|
return MapItemManager.createMapItem(poster, poster.getIndex(mapId));
|
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
|
2015-09-10 18:17:35 +02:00
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected ItemStack getEmptyViewItem() {
|
|
|
|
|
if (map instanceof SingleMap) {
|
2015-09-10 18:17:35 +02:00
|
|
|
|
return getViewItem(0, 0);
|
2020-12-10 22:13:05 +01:00
|
|
|
|
} else {
|
|
|
|
|
return super.getEmptyViewItem();
|
2015-09-10 18:17:35 +02:00
|
|
|
|
}
|
2015-08-31 11:36:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-12-10 22:13:05 +01:00
|
|
|
|
protected void onUpdate() {
|
2016-05-21 18:55:32 +02:00
|
|
|
|
/// Title of the map details GUI
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (offplayer.getUniqueId().equals(getPlayer().getUniqueId())) {
|
2020-08-27 01:32:04 +02:00
|
|
|
|
setTitle(I.t(getPlayerLocale(), "Your maps » {black}{0}", map.getName()));
|
2020-12-10 22:13:05 +01:00
|
|
|
|
} else {
|
|
|
|
|
setTitle(I.t(getPlayerLocale(), "{1}'s maps » {black}{0}", map.getName(), name));
|
2020-08-27 01:32:04 +02:00
|
|
|
|
}
|
2015-09-10 18:17:35 +02:00
|
|
|
|
setKeepHorizontalScrollingSpace(true);
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (map instanceof PosterMap) {
|
2016-07-07 02:04:13 +02:00
|
|
|
|
PosterMap poster = (PosterMap) map;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (poster.hasColumnData()) {
|
2016-07-07 02:04:13 +02:00
|
|
|
|
setDataShape(poster.getColumnCount(), poster.getRowCount());
|
2020-12-10 22:13:05 +01:00
|
|
|
|
} else {
|
2016-07-07 02:04:13 +02:00
|
|
|
|
setData(ArrayUtils.toObject(poster.getMapsIDs()));
|
|
|
|
|
}
|
2020-12-10 22:13:05 +01:00
|
|
|
|
} else {
|
|
|
|
|
setDataShape(1, 1);
|
2016-07-07 02:04:13 +02:00
|
|
|
|
}
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2018-01-24 00:16:58 +01:00
|
|
|
|
final boolean canRename = Permissions.RENAME.grantedTo(getPlayer());
|
|
|
|
|
final boolean canDelete = Permissions.DELETE.grantedTo(getPlayer());
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2018-01-24 00:16:58 +01:00
|
|
|
|
int renameSlot = getSize() - 7;
|
|
|
|
|
int deleteSlot = getSize() - 6;
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (!canRename) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
deleteSlot--;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
}
|
2018-01-24 00:16:58 +01:00
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (canRename) {
|
2019-10-26 14:26:12 +02:00
|
|
|
|
action("rename", renameSlot, new ItemStackBuilder(Material.WRITABLE_BOOK)
|
2018-01-24 00:16:58 +01:00
|
|
|
|
.title(I.t(getPlayerLocale(), "{blue}Rename this image"))
|
2020-12-10 22:13:05 +01:00
|
|
|
|
.longLore(I.t(getPlayerLocale(),
|
|
|
|
|
"{gray}Click here to rename this image; this is used for your own organization."))
|
2018-01-24 00:16:58 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (canDelete) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
action("delete", deleteSlot, new ItemStackBuilder(Material.BARRIER)
|
|
|
|
|
.title(I.t(getPlayerLocale(), "{red}Delete this image"))
|
2020-12-10 22:13:05 +01:00
|
|
|
|
.longLore(I.t(getPlayerLocale(),
|
|
|
|
|
"{gray}Deletes this map {white}forever{gray}. This action cannot be undone!"))
|
2018-01-24 00:16:58 +01:00
|
|
|
|
.loreLine()
|
2020-12-10 22:13:05 +01:00
|
|
|
|
.longLore(
|
|
|
|
|
I.t(getPlayerLocale(), "{gray}You will be asked to confirm your choice if you click here."))
|
2018-01-24 00:16:58 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To keep the controls centered, the back button is shifted to the right when the
|
|
|
|
|
// arrow isn't displayed, so when the map fit on the grid without sliders.
|
|
|
|
|
int backSlot = getSize() - 4;
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
if (!canRename && !canDelete) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
backSlot = getSize() - 5;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
} else if (map instanceof PosterMap && ((PosterMap) map).getColumnCount() <= INVENTORY_ROW_SIZE) {
|
2015-09-10 18:17:35 +02:00
|
|
|
|
backSlot++;
|
2020-12-10 22:13:05 +01:00
|
|
|
|
}
|
2015-09-10 18:17:35 +02:00
|
|
|
|
|
2016-05-21 18:55:32 +02:00
|
|
|
|
action("back", backSlot, new ItemStackBuilder(Material.EMERALD)
|
2016-07-08 04:45:08 +02:00
|
|
|
|
.title(I.t(getPlayerLocale(), "{green}« Back"))
|
2017-03-12 20:12:35 +01:00
|
|
|
|
.lore(I.t(getPlayerLocale(), "{gray}Go back to the list."))
|
2016-05-21 18:55:32 +02:00
|
|
|
|
);
|
2015-12-29 19:12:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
@GuiAction("rename")
|
|
|
|
|
public void rename() {
|
|
|
|
|
if (!Permissions.RENAME.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
|
|
|
|
|
update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 00:26:27 +02:00
|
|
|
|
try {
|
|
|
|
|
PromptGui.prompt(getPlayer(), newName -> {
|
|
|
|
|
if (!Permissions.RENAME.grantedTo(getPlayer())) {
|
|
|
|
|
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newName == null || newName.isEmpty()) {
|
|
|
|
|
I.sendT(getPlayer(), "{ce}Map names can't be empty.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (newName.equals(map.getName())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map.rename(newName);
|
|
|
|
|
I.sendT(getPlayer(), "{cs}Map successfully renamed.");
|
|
|
|
|
|
|
|
|
|
if (getParent() != null) {
|
|
|
|
|
RunTask.later(() -> Gui.open(getPlayer(), this), 1L);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}, map.getName(), this);
|
|
|
|
|
|
|
|
|
|
} catch (IllegalStateException e) {
|
2021-11-14 13:39:29 +01:00
|
|
|
|
PluginLogger.error("Error while renaming map: ", e);
|
2021-09-03 00:26:27 +02:00
|
|
|
|
}
|
2015-12-29 19:12:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
@GuiAction("delete")
|
|
|
|
|
public void delete() {
|
|
|
|
|
if (!Permissions.DELETE.grantedTo(getPlayer())) {
|
2018-01-24 00:16:58 +01:00
|
|
|
|
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
|
|
|
|
|
update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-29 19:12:36 +01:00
|
|
|
|
Gui.open(getPlayer(), new ConfirmDeleteMapGui(map), this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 22:13:05 +01:00
|
|
|
|
@GuiAction("back")
|
|
|
|
|
public void back() {
|
2015-12-29 19:12:36 +01:00
|
|
|
|
close();
|
2015-08-31 11:36:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|