Compare commits

..

3 Commits

31 changed files with 1112 additions and 167 deletions

View File

@ -31,7 +31,7 @@ import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import org.bukkit.Chunk;
import org.bukkit.World;
@ -65,7 +65,7 @@ final class BlockStatePopulator extends BlockPopulator {
return;
}
final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
final ZeroedDelegateScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z,
final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z,
com.plotsquared.bukkit.util.BukkitWorld.getMinWorldHeight(world),
com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(world) - 1
);

View File

@ -35,7 +35,7 @@ import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.ChunkManager;
import com.sk89q.worldedit.math.BlockVector2;
import org.bukkit.World;
@ -198,7 +198,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
return result.getChunkData();
}
private void generate(BlockVector2 loc, World world, ZeroedDelegateScopedQueueCoordinator result) {
private void generate(BlockVector2 loc, World world, ScopedQueueCoordinator result) {
// Load if improperly loaded
if (!this.loaded) {
String name = world.getName();

View File

@ -31,7 +31,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import org.bukkit.World;
@ -67,7 +67,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
}
@Override
public void generateChunk(final ZeroedDelegateScopedQueueCoordinator result, PlotArea settings) {
public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) {
World world = BukkitUtil.getWorld(this.world);
Location min = result.getMin();
int chunkX = min.getX() >> 4;

View File

@ -28,6 +28,7 @@ package com.plotsquared.bukkit.inject;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.listener.SingleWorldListener;
@ -43,6 +44,8 @@ import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.fawe.FaweRegionManager;
import com.plotsquared.bukkit.util.fawe.FaweSchematicHandler;
import com.plotsquared.bukkit.util.gui.BukkitPlotInventory;
import com.plotsquared.bukkit.util.gui.BukkitPlotInventoryProvider;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
@ -70,6 +73,7 @@ import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.gui.PlotInventoryProvider;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Actor;
import org.apache.logging.log4j.LogManager;
@ -103,6 +107,7 @@ public class BukkitModule extends AbstractModule {
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
bind(SetupUtils.class).to(BukkitSetupUtils.class);
bind(WorldUtil.class).to(BukkitUtil.class);
bind(new TypeLiteral<PlotInventoryProvider<?, ?>>(){}).to(BukkitPlotInventoryProvider.class);
install(new FactoryModuleBuilder()
.implement(ProgressSubscriber.class, DefaultProgressSubscriber.class)
.build(ProgressSubscriberFactory.class));

View File

@ -364,6 +364,11 @@ public class BukkitPlayer extends PlotPlayer<Player> {
}
}
@Override
public void closeInventory() {
this.player.closeInventory();
}
/**
* Convert from PlotSquared's {@link TeleportCause} to Bukkit's {@link PlayerTeleportEvent.TeleportCause}
*

View File

@ -30,7 +30,7 @@ import com.plotsquared.bukkit.util.BukkitBlockUtil;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.AnnotationHelper;
import com.plotsquared.core.util.ChunkUtil;
import com.plotsquared.core.util.PatternUtil;
@ -52,7 +52,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays;
@AnnotationHelper.ApiDescription(info = "Internal use only. Subject to changes at any time.")
public class GenChunk extends ZeroedDelegateScopedQueueCoordinator {
public class GenChunk extends ScopedQueueCoordinator {
public final Biome[] biomes;
public BlockState[][] result;

View File

@ -37,7 +37,7 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.WorldUtil;
@ -264,9 +264,9 @@ public class BukkitRegionManager extends RegionManager {
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
AugmentedUtils.bypass(
ignoreAugment,
() -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ZeroedDelegateScopedQueueCoordinator>() {
() -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
@Override
public void run(ZeroedDelegateScopedQueueCoordinator value) {
public void run(ScopedQueueCoordinator value) {
Location min = value.getMin();
int bx = min.getX();
int bz = min.getZ();

View File

@ -0,0 +1,170 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.util.gui;
import com.google.common.base.Preconditions;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotItemStack;
import com.plotsquared.core.util.gui.PlotInventory;
import com.plotsquared.core.util.gui.PlotInventoryClickHandler;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.WeakHashMap;
/**
* Implementation of the {@link PlotInventory} for the bukkit platform.
*/
public class BukkitPlotInventory extends PlotInventory<Player, ItemStack> {
private static Listener INVENTORY_LISTENER;
private static final Map<UUID, BukkitPlotInventory> INVENTORIES = new WeakHashMap<>();
private final ItemStack[] items;
final PlotInventoryClickHandler[] clickHandlers;
Inventory nativeInventory;
/**
* {@inheritDoc}
*/
protected BukkitPlotInventory(
PlotPlayer<Player> player, final int size, final Caption titleCaption,
final TagResolver... titleResolvers
) {
super(player, size, titleCaption, titleResolvers);
this.items = new ItemStack[size];
this.clickHandlers = new PlotInventoryClickHandler[size];
this.nativeInventory = Bukkit.createInventory(player.getPlatformPlayer(), size(),
BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessage.miniMessage().deserialize(
titleCaption().getComponent(player), titleResolvers()
))
);
if (INVENTORY_LISTENER == null) {
INVENTORY_LISTENER = new BukkitPlotInventoryListener(INVENTORIES);
BukkitPlatform bukkitPlatform = ((BukkitPlatform) PlotSquared.platform());
bukkitPlatform.getServer().getPluginManager().registerEvents(INVENTORY_LISTENER, bukkitPlatform);
}
}
@Override
public void setItem(final int slot, final PlotItemStack item, final PlotInventoryClickHandler onClick) {
Preconditions.checkElementIndex(slot, size(), "Slot must be in range (0, " + size() + ")");
this.items[slot] = toPlatformItem(item);
this.clickHandlers[slot] = onClick;
this.nativeInventory.setItem(slot, this.items[slot]);
}
@Override
public void addItem(final PlotItemStack item, final PlotInventoryClickHandler onClick) {
// TODO: probably needs more love (who doesn't)
int slot = -1;
// try to fill stacks
for (int i = 0; i < items.length; i++) {
if (Objects.equals(items[i], toPlatformItem(item))) {
slot = i;
break;
}
}
// search for empty slots
if (slot == -1) {
for (int i = 0; i < items.length; i++) {
if (items[i] == null || items[i].getType() == Material.AIR) {
slot = i;
break;
}
}
}
Preconditions.checkElementIndex(slot, size());
this.items[slot] = toPlatformItem(item);
this.clickHandlers[slot] = onClick;
this.nativeInventory.setItem(slot, this.items[slot]);
}
@Override
public void open() {
INVENTORIES.put(player().getUUID(), this);
player().getPlatformPlayer().openInventory(this.nativeInventory);
}
@Override
public void close() {
if (Objects.equals(player().getPlatformPlayer().getOpenInventory().getTopInventory(), this.nativeInventory)) {
player().getPlatformPlayer().closeInventory();
}
}
@Override
public ItemStack toPlatformItem(final PlotItemStack item) {
if (item == null) {
return null;
}
Material material = BukkitAdapter.adapt(item.getType());
if (material == null) {
return null;
}
ItemStack stack = new ItemStack(material, item.getAmount());
ItemMeta meta = null;
if (item.getName() != null) {
meta = stack.getItemMeta();
Component nameComponent = BukkitUtil.MINI_MESSAGE.deserialize(item.getName());
meta.setDisplayName(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(nameComponent));
}
if (item.getLore() != null) {
if (meta == null) {
meta = stack.getItemMeta();
}
List<String> lore = new ArrayList<>();
for (String entry : item.getLore()) {
lore.add(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(BukkitUtil.MINI_MESSAGE.deserialize(entry)));
}
meta.setLore(lore);
}
if (meta != null) {
stack.setItemMeta(meta);
}
return stack;
}
}

View File

@ -0,0 +1,112 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.util.gui;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotItemStack;
import com.plotsquared.core.util.gui.PlotInventoryClickHandler;
import com.plotsquared.core.util.gui.PlotInventoryClickType;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
public class BukkitPlotInventoryListener implements Listener {
private static final EnumMap<ClickType, PlotInventoryClickType> CLICK_MAPPING = new EnumMap<>(ClickType.class);
static {
CLICK_MAPPING.put(ClickType.LEFT, PlotInventoryClickType.LEFT);
CLICK_MAPPING.put(ClickType.RIGHT, PlotInventoryClickType.RIGHT);
CLICK_MAPPING.put(ClickType.SHIFT_LEFT, PlotInventoryClickType.SHIFT_LEFT);
CLICK_MAPPING.put(ClickType.SHIFT_RIGHT, PlotInventoryClickType.SHIFT_RIGHT);
CLICK_MAPPING.put(ClickType.MIDDLE, PlotInventoryClickType.MIDDLE);
}
private final Map<UUID, BukkitPlotInventory> inventories;
public BukkitPlotInventoryListener(final Map<UUID, BukkitPlotInventory> inventories) {
this.inventories = inventories;
}
@EventHandler
public void onInventoryClick(final org.bukkit.event.inventory.InventoryClickEvent event) {
final PlotPlayer<Player> player = BukkitUtil.adapt((Player) event.getWhoClicked());
BukkitPlotInventory currentInventory = inventories.get(player.getUUID());
if (currentInventory == null) {
return;
}
if (!Objects.equals(event.getClickedInventory(), currentInventory.nativeInventory)) {
return;
}
final int slot = event.getRawSlot();
if (slot < 0 || slot >= currentInventory.size()) {
return;
}
PlotInventoryClickType clickType = CLICK_MAPPING.getOrDefault(event.getClick(), PlotInventoryClickType.OTHER);
event.setCancelled(true);
final PlotInventoryClickHandler clickHandler = currentInventory.clickHandlers[slot];
if (clickHandler == null) {
return;
}
final ItemStack item = event.getCurrentItem();
if (item == null) {
clickHandler.handle(null, clickType);
return;
}
clickHandler.handle(new PlotItemStack(
BukkitAdapter.asItemType(item.getType()),
item.getAmount(),
item.getItemMeta().getDisplayName(),
item.getItemMeta().hasLore() ? item.getItemMeta().getLore().toArray(String[]::new) : new String[0]
), clickType);
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
final PlotPlayer<Player> player = BukkitUtil.adapt((Player) event.getPlayer());
BukkitPlotInventory currentInventory = inventories.get(player.getUUID());
if (currentInventory == null) {
return;
}
currentInventory.nativeInventory = null;
inventories.remove(player.getUUID());
}
}

View File

@ -0,0 +1,48 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.bukkit.util.gui;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.gui.PlotInventory;
import com.plotsquared.core.util.gui.PlotInventoryProvider;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class BukkitPlotInventoryProvider implements PlotInventoryProvider<Player, ItemStack> {
@Override
public PlotInventory<Player, ItemStack> createInventory(
PlotPlayer<?> player,
final int size,
final Caption titleCaption,
final TagResolver... titleResolvers
) {
return new BukkitPlotInventory((PlotPlayer<Player>) player, size, titleCaption, titleResolvers);
}
}

View File

@ -430,7 +430,8 @@ public class Area extends SubCommand {
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
queue.setChunkConsumer(chunk -> AugmentedUtils.generateChunk(
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
null,
world,
chunk.getX(),
chunk.getZ(),
@ -802,7 +803,8 @@ public class Area extends SubCommand {
return false;
}
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
queue.setChunkConsumer(chunk -> AugmentedUtils.generateChunk(
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
null,
area.getWorldName(),
chunk.getX(),
chunk.getZ(),

View File

@ -27,32 +27,18 @@ package com.plotsquared.core.command;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.gui.PlotMusicInventory;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotInventory;
import com.plotsquared.core.plot.PlotItemStack;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.MusicFlag;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.Permissions;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.kyori.adventure.text.Component;
import com.plotsquared.core.util.gui.PlotInventoryProvider;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
@CommandDeclaration(command = "music",
permission = "plots.music",
usage = "/plot music",
@ -60,20 +46,16 @@ import java.util.Locale;
requiredType = RequiredType.PLAYER)
public class Music extends SubCommand {
private static final Collection<String> DISCS = Arrays
.asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp",
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait", "music_disc_otherside",
"music_disc_pigstep"
);
private final InventoryUtil inventoryUtil;
private final EventDispatcher eventDispatcher;
private final PlotInventoryProvider<?, ?> inventoryProvider;
@Inject
public Music(final @Nullable InventoryUtil inventoryUtil, final @NonNull EventDispatcher eventDispatcher) {
this.inventoryUtil = inventoryUtil;
public Music(
final @NonNull EventDispatcher eventDispatcher,
final PlotInventoryProvider<?, ?> inventoryProvider
) {
this.eventDispatcher = eventDispatcher;
this.inventoryProvider = inventoryProvider;
}
@Override
@ -99,85 +81,8 @@ public class Music extends SubCommand {
);
return true;
}
PlotInventory inv = new PlotInventory(
this.inventoryUtil,
player,
2,
TranslatableCaption.of("plotjukebox.jukebox_header").getComponent(player)
) {
@Override
public boolean onClick(int index) {
PlotItemStack item = getItem(index);
if (item == null) {
return true;
}
if (item.getType() == ItemTypes.BEDROCK) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
.createFlagInstance(item.getType());
PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
getPlayer().sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Music removal")))
);
return true;
}
plot.removeFlag(event.getFlag());
getPlayer().sendMessage(
TranslatableCaption.of("flag.flag_removed"),
TagResolver.builder()
.tag("flag", Tag.inserting(Component.text("music")))
.tag("value", Tag.inserting(Component.text("music_disc")))
.build()
);
} else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
.createFlagInstance(item.getType());
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
getPlayer().sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Music addition")))
);
return true;
}
plot.setFlag(event.getFlag());
getPlayer().sendMessage(
TranslatableCaption.of("flag.flag_added"),
TagResolver.builder()
.tag("flag", Tag.inserting(Component.text("music")))
.tag("value", Tag.inserting(Component.text(event.getFlag().getValue().toString())))
.build()
);
} else {
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_not_added"));
}
return false;
}
};
int index = 0;
for (final String disc : DISCS) {
final String name = String.format("<gold>%s</gold>", disc);
final String[] lore = {TranslatableCaption.of("plotjukebox.click_to_play").getComponent(player)};
ItemType type = ItemTypes.get(disc);
if (type == null) {
continue;
}
final PlotItemStack item = new PlotItemStack(type, 1, name, lore);
if (inv.setItemChecked(index, item)) {
index++;
}
}
// Always add the cancel button
// if (player.getMeta("music") != null) {
String name = TranslatableCaption.of("plotjukebox.cancel_music").getComponent(player);
String[] lore = {TranslatableCaption.of("plotjukebox.reset_music").getComponent(player)};
inv.setItem(index, new PlotItemStack("bedrock", 1, name, lore));
// }
inv.openInventory();
new PlotMusicInventory<>(inventoryProvider, player, plot, eventDispatcher).open();
return true;
}

View File

@ -34,7 +34,7 @@ import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator;
import com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.RegionUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockState;
@ -168,8 +168,8 @@ public class AugmentedUtils {
// This queue should not be enqueued as it is simply used to restrict block setting, and then delegate to the
// actual queue
ZeroedDelegateScopedQueueCoordinator scoped =
new ZeroedDelegateScopedQueueCoordinator(
ScopedQueueCoordinator scoped =
new ScopedQueueCoordinator(
secondaryMask,
Location.at(world, blockX, area.getMinGenHeight(), blockZ),
Location.at(world, blockX + 15, area.getMaxGenHeight(), blockZ + 15)
@ -183,4 +183,19 @@ public class AugmentedUtils {
return generationResult;
}
/**
* @deprecated Use {@link AugmentedUtils#generateChunk(String, int, int, QueueCoordinator)} as chunkObject is not required
* in the above method
*/
@Deprecated(forRemoval = true, since = "6.8.0")
public static boolean generate(
@Nullable Object chunkObject,
final @NonNull String world,
final int chunkX,
final int chunkZ,
QueueCoordinator queue
) {
return generateChunk(world, chunkX, chunkZ, queue);
}
}

View File

@ -33,7 +33,7 @@ import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -55,16 +55,12 @@ public class HybridGen extends IndependentPlotGenerator {
}
private void placeSchem(
HybridPlotWorld world,
ZeroedDelegateScopedQueueCoordinator result,
short relativeX,
short relativeZ,
int x,
int z,
boolean isRoad
HybridPlotWorld world, ScopedQueueCoordinator result, short relativeX,
short relativeZ, int x, int z, boolean isRoad
) {
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad && Settings.Schematics.PASTE_ON_TOP)) {
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad
&& Settings.Schematics.PASTE_ON_TOP)) {
minY = world.SCHEM_Y;
} else {
minY = world.getMinBuildHeight();
@ -84,7 +80,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
@Override
public void generateChunk(@NonNull ZeroedDelegateScopedQueueCoordinator result, @NonNull PlotArea settings) {
public void generateChunk(@NonNull ScopedQueueCoordinator result, @NonNull PlotArea settings) {
Preconditions.checkNotNull(result, "result cannot be null");
Preconditions.checkNotNull(settings, "settings cannot be null");

View File

@ -594,6 +594,20 @@ public class HybridUtils {
return ey;
}
/**
* Regenerate the road in a chunk in a plot area.
*
* @param area Plot area to regenerate road for
* @param chunk Chunk location to regenerate
* @param extend How far to extend setting air above the road
* @return if successful
* @deprecated use {@link HybridUtils#regenerateRoad(PlotArea, BlockVector2, int, QueueCoordinator)}
*/
@Deprecated(forRemoval = true, since = "6.6.0")
public boolean regenerateRoad(final PlotArea area, final BlockVector2 chunk, int extend) {
return regenerateRoad(area, chunk, extend, null);
}
/**
* Regenerate the road in a chunk in a plot area.
*

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.setup.PlotAreaBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -54,9 +54,9 @@ public abstract class IndependentPlotGenerator {
* @param result queue
* @param settings PlotArea (settings)
*/
public abstract void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings);
public abstract void generateChunk(ScopedQueueCoordinator result, PlotArea settings);
public boolean populateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea setting) {
public boolean populateChunk(ScopedQueueCoordinator result, PlotArea setting) {
return false;
}

View File

@ -32,7 +32,7 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -59,7 +59,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
}
@Override
public void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings) {
public void generateChunk(ScopedQueueCoordinator result, PlotArea settings) {
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
Location min = result.getMin();

View File

@ -0,0 +1,145 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.gui;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotItemStack;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.MusicFlag;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.gui.ExtendablePlotInventory;
import com.plotsquared.core.util.gui.PlotInventoryProvider;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import java.util.List;
import java.util.stream.Stream;
public class PlotMusicInventory<P, I> extends ExtendablePlotInventory<P, I> {
private static final List<String> DISCS = Stream.of(
"music_disc_13",
"music_disc_cat",
"music_disc_blocks",
"music_disc_chirp",
"music_disc_far",
"music_disc_mall",
"music_disc_mellohi",
"music_disc_stal",
"music_disc_strad",
"music_disc_ward",
"music_disc_11",
"music_disc_wait",
"music_disc_otherside",
"music_disc_pigstep"
).filter(s -> ItemTypes.get(s) != null).toList();
private final Plot plot;
private final EventDispatcher eventDispatcher;
public PlotMusicInventory(
final PlotInventoryProvider<P, I> provider,
PlotPlayer<?> player,
Plot plot,
EventDispatcher eventDispatcher
) {
super(
provider, player, 2 * 9,
TranslatableCaption.of("plotjukebox.jukebox_header")
);
this.plot = plot;
this.eventDispatcher = eventDispatcher;
setDiscs();
setCancelButton();
}
private void setDiscs() {
for (final String disc : DISCS) {
PlotItemStack itemStack = new PlotItemStack(
disc, 1, String.format("<gold>%s</gold>", disc),
TranslatableCaption.of("plotjukebox.click_to_play").getComponent(player())
);
addItem(itemStack, (item, type) -> {
close();
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
.createFlagInstance(item.getType());
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
player().sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Music addition")))
);
return;
}
plot.setFlag(event.getFlag());
player().sendMessage(
TranslatableCaption.of("flag.flag_added"),
TagResolver.builder()
.tag("flag", Tag.inserting(Component.text("music")))
.tag("value", Tag.inserting(Component.text(event.getFlag().getValue().toString())))
.build()
);
});
}
}
private void setCancelButton() {
PlotItemStack cancelItem = new PlotItemStack(
ItemTypes.BEDROCK, 1,
TranslatableCaption.of("plotjukebox.cancel_music").getComponent(player()),
TranslatableCaption.of("plotjukebox.reset_music").getComponent(player())
);
setItem(size() - 1, cancelItem, (item, type) -> {
close();
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
.createFlagInstance(item.getType());
PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
player().sendMessage(
TranslatableCaption.of("events.event_denied"),
TagResolver.resolver("value", Tag.inserting(Component.text("Music removal")))
);
return;
}
plot.removeFlag(event.getFlag());
player().sendMessage(
TranslatableCaption.of("flag.flag_removed"),
TagResolver.builder()
.tag("flag", Tag.inserting(Component.text("music")))
.tag("value", Tag.inserting(Component.text("music_disc")))
.build()
);
});
}
}

View File

@ -258,4 +258,8 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
return true;
}
@Override
public void closeInventory() {
}
}

View File

@ -1015,6 +1015,12 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
public @NonNull
abstract Audience getAudience();
/**
* Closes the current open inventory, if present
* @since TODO
*/
public abstract void closeInventory();
/**
* Get this player's {@link LockRepository}
*

View File

@ -45,7 +45,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* {@link BlockArrayCacheScopedQueueCoordinator#setOffsetZ(int)}
*/
@AnnotationHelper.ApiDescription(info = "Internal use only. Subject to change at any time and created for specific use cases.")
public class BlockArrayCacheScopedQueueCoordinator extends ZeroedDelegateScopedQueueCoordinator {
public class BlockArrayCacheScopedQueueCoordinator extends ScopedQueueCoordinator {
private final BlockState[][][] blockStates;
private final int height;

View File

@ -0,0 +1,170 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.queue;
import com.plotsquared.core.location.Location;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Queue that is limited to a single chunk. It does not allow a delegate queue and should be treated as a cache for changes to
* be set to. Does not support tile entities or entities.
*
* @deprecated This class is poorly designed and will no longer be used in P2
*/
@Deprecated(forRemoval = true, since = "6.8.0")
public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
public final BiomeType[][][] biomeResult;
public final BlockState[][][] result;
private final int width;
private final int length;
private final BlockVector3 bot;
private final BlockVector3 top;
private final World weWorld;
public ChunkQueueCoordinator(
final @NonNull World weWorld,
@NonNull BlockVector3 bot,
@NonNull BlockVector3 top,
boolean biomes
) {
super(null, Location.at("", 0, weWorld.getMinY(), 0), Location.at("", 15, weWorld.getMaxY(), 15));
this.weWorld = weWorld;
this.width = top.getX() - bot.getX() + 1;
this.length = top.getZ() - bot.getZ() + 1;
this.result = new BlockState[weWorld.getMaxY() - weWorld.getMinY() + 1][width][length];
this.biomeResult = biomes ? new BiomeType[weWorld.getMaxY() - weWorld.getMinY() + 1][width][length] : null;
this.bot = bot;
this.top = top;
}
public @NonNull BlockState[][][] getBlocks() {
return result;
}
@Override
public boolean setBiome(int x, int z, @NonNull BiomeType biomeType) {
if (this.biomeResult != null) {
for (int y = weWorld.getMinY(); y <= weWorld.getMaxY(); y++) {
this.storeCacheBiome(x, y, z, biomeType);
}
return true;
}
return false;
}
@Override
public boolean setBiome(int x, int y, int z, @NonNull BiomeType biomeType) {
if (this.biomeResult != null) {
this.storeCacheBiome(x, y, z, biomeType);
return true;
}
return false;
}
@Override
public boolean setBlock(int x, int y, int z, @NonNull BlockState id) {
this.storeCache(x, y, z, id);
return true;
}
@Override
public boolean setBlock(int x, int y, int z, @NonNull Pattern pattern) {
this.storeCache(x, y, z, pattern.applyBlock(BlockVector3.at(x, y, z)).toImmutableState());
return true;
}
private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) {
int yIndex = getYIndex(y);
BlockState[][] resultY = result[yIndex];
if (resultY == null) {
result[yIndex] = resultY = new BlockState[length][];
}
BlockState[] resultYZ = resultY[z];
if (resultYZ == null) {
resultY[z] = resultYZ = new BlockState[width];
}
resultYZ[x] = id;
}
private void storeCacheBiome(final int x, final int y, final int z, final @NonNull BiomeType id) {
int yIndex = getYIndex(y);
BiomeType[][] resultY = biomeResult[yIndex];
if (resultY == null) {
biomeResult[yIndex] = resultY = new BiomeType[length][];
}
BiomeType[] resultYZ = resultY[z];
if (resultYZ == null) {
resultY[z] = resultYZ = new BiomeType[width];
}
resultYZ[x] = id;
}
@Override
public boolean setBlock(int x, int y, int z, final @NonNull BaseBlock id) {
this.storeCache(x, y, z, id.toImmutableState());
return true;
}
@Override
public @Nullable BlockState getBlock(int x, int y, int z) {
BlockState[][] blocksY = result[getYIndex(y)];
if (blocksY != null) {
BlockState[] blocksYZ = blocksY[z];
if (blocksYZ != null) {
return blocksYZ[x];
}
}
return null;
}
@Override
public @Nullable World getWorld() {
return weWorld;
}
@Override
public @NonNull Location getMax() {
return Location.at(getWorld().getName(), top.getX(), top.getY(), top.getZ());
}
@Override
public @NonNull Location getMin() {
return Location.at(getWorld().getName(), bot.getX(), bot.getY(), bot.getZ());
}
private int getYIndex(int y) {
return y - weWorld.getMinY();
}
}

View File

@ -71,17 +71,33 @@ public abstract class QueueCoordinator {
}
/**
* Get a {@link ZeroedDelegateScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
* Get a {@link ScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
*
* @param x chunk x coordinate
* @param z chunk z coordinate
* @return a new {@link ZeroedDelegateScopedQueueCoordinator}
* @since TODO
* @return a new {@link ScopedQueueCoordinator}
* @deprecated Use {@link ScopedQueueCoordinator#getForChunk(int, int, int, int)}
*/
public ZeroedDelegateScopedQueueCoordinator getForChunk(int x, int z, int minY, int maxY) {
@Deprecated(forRemoval = true, since = "6.6.0")
public ScopedQueueCoordinator getForChunk(int x, int z) {
if (getWorld() == null) {
return getForChunk(x, z, PlotSquared.platform().versionMinHeight(), PlotSquared.platform().versionMaxHeight());
}
return getForChunk(x, z, getWorld().getMinY(), getWorld().getMaxY());
}
/**
* Get a {@link ScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
*
* @param x chunk x coordinate
* @param z chunk z coordinate
* @return a new {@link ScopedQueueCoordinator}
* @since 6.6.0
*/
public ScopedQueueCoordinator getForChunk(int x, int z, int minY, int maxY) {
int bx = x << 4;
int bz = z << 4;
return new ZeroedDelegateScopedQueueCoordinator(this, Location.at(getWorld().getName(), bx, minY, bz),
return new ScopedQueueCoordinator(this, Location.at(getWorld().getName(), bx, minY, bz),
Location.at(getWorld().getName(), bx + 15, maxY, bz + 15)
);
}

View File

@ -35,13 +35,13 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Queue that only sets blocks with a designated X-Z area, will accept any Y values. Requires all blocks be set normalized to
* zero in the x and z directions, i.e. starting from 0,0. An offset of the minimum point of the region will then be applied to
* x and z.
* Queue that only sets blocks with a designated X-Z area, will accept any Y values. Requires all blocks be set normalized in
* the x and z directions, i.e. starting from 0,0. An offset of the minimum point of the region will then be applied to x and z.
*
* @since TODO
* @deprecated This should be renamed to NormalizedScopedQueueCoordinator or something.
*/
public class ZeroedDelegateScopedQueueCoordinator extends DelegateQueueCoordinator {
@Deprecated(forRemoval = true, since = "6.8.0")
public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
private final Location min;
private final Location max;
@ -56,10 +56,8 @@ public class ZeroedDelegateScopedQueueCoordinator extends DelegateQueueCoordinat
/**
* Create a new ScopedQueueCoordinator instance that delegates to a given QueueCoordinator. Locations are inclusive.
*
* @since TODO
*/
public ZeroedDelegateScopedQueueCoordinator(@Nullable QueueCoordinator parent, @NonNull Location min, @NonNull Location max) {
public ScopedQueueCoordinator(@Nullable QueueCoordinator parent, @NonNull Location min, @NonNull Location max) {
super(parent);
this.min = min;
this.max = max;

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.task.RunnableVal;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.world.World;
@ -39,12 +39,12 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class ChunkManager {
private static final Map<BlockVector2, RunnableVal<ZeroedDelegateScopedQueueCoordinator>> forceChunks = new ConcurrentHashMap<>();
private static final Map<BlockVector2, RunnableVal<ZeroedDelegateScopedQueueCoordinator>> addChunks = new ConcurrentHashMap<>();
private static final Map<BlockVector2, RunnableVal<ScopedQueueCoordinator>> forceChunks = new ConcurrentHashMap<>();
private static final Map<BlockVector2, RunnableVal<ScopedQueueCoordinator>> addChunks = new ConcurrentHashMap<>();
public static void setChunkInPlotArea(
RunnableVal<ZeroedDelegateScopedQueueCoordinator> force,
RunnableVal<ZeroedDelegateScopedQueueCoordinator> add,
RunnableVal<ScopedQueueCoordinator> force,
RunnableVal<ScopedQueueCoordinator> add,
String world,
BlockVector2 loc
) {
@ -53,8 +53,8 @@ public abstract class ChunkManager {
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) {
int blockX = loc.getX() << 4;
int blockZ = loc.getZ() << 4;
ZeroedDelegateScopedQueueCoordinator scoped =
new ZeroedDelegateScopedQueueCoordinator(
ScopedQueueCoordinator scoped =
new ScopedQueueCoordinator(
queue,
Location.at(world, blockX, weWorld.getMinY(), blockZ),
Location.at(world, blockX + 15, weWorld.getMaxY(), blockZ + 15)
@ -79,11 +79,8 @@ public abstract class ChunkManager {
}
}
/**
* @since TODO
*/
public static boolean preProcessChunk(BlockVector2 loc, ZeroedDelegateScopedQueueCoordinator queue) {
final RunnableVal<ZeroedDelegateScopedQueueCoordinator> forceChunk = forceChunks.get(loc);
public static boolean preProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) {
final RunnableVal<ScopedQueueCoordinator> forceChunk = forceChunks.get(loc);
if (forceChunk != null) {
forceChunk.run(queue);
forceChunks.remove(loc);
@ -92,11 +89,8 @@ public abstract class ChunkManager {
return false;
}
/**
* @since TODO
*/
public static boolean postProcessChunk(BlockVector2 loc, ZeroedDelegateScopedQueueCoordinator queue) {
final RunnableVal<ZeroedDelegateScopedQueueCoordinator> addChunk = forceChunks.get(loc);
public static boolean postProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) {
final RunnableVal<ScopedQueueCoordinator> addChunk = forceChunks.get(loc);
if (addChunk != null) {
addChunk.run(queue);
addChunks.remove(loc);

View File

@ -0,0 +1,74 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util.gui;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotItemStack;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
public class ExtendablePlotInventory<P, I> extends PlotInventory<P, I> {
private final PlotInventory<P, I> delegate;
public ExtendablePlotInventory(PlotInventory<P, I> delegate) {
super(delegate.player(), delegate.size(), delegate.titleCaption(), delegate.titleResolvers());
this.delegate = delegate;
}
public ExtendablePlotInventory(
PlotInventoryProvider<P, I> provider, PlotPlayer<?> player, int size, Caption title,
TagResolver... titleResolver
) {
this(provider.createInventory(player, size, title, titleResolver));
}
@Override
public void setItem(final int slot, final PlotItemStack item, final PlotInventoryClickHandler onClick) {
delegate.setItem(slot, item, onClick);
}
@Override
public void addItem(final PlotItemStack item, final PlotInventoryClickHandler onClick) {
delegate.addItem(item, onClick);
}
@Override
public void open() {
delegate.open();
}
@Override
public void close() {
delegate.close();
}
@Override
public I toPlatformItem(final PlotItemStack item) {
return delegate.toPlatformItem(item);
}
}

View File

@ -0,0 +1,145 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util.gui;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotItemStack;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
/**
* @param <P> The platform player
* @param <I> The platform item object
* @since TODO
*/
public abstract class PlotInventory<P, I> {
private final PlotInventoryClickHandler NOOP_CLICK_HANDLER = (x, y) -> {
};
private final PlotPlayer<P> player;
private final int size;
private final Caption titleCaption;
private final TagResolver[] titleResolvers;
/**
* Instantiates a new Plot inventory.
*
* @param size The size of the inventory - must be a multiple of 9
* @param titleCaption The caption to use for the title
* @param titleResolvers The tag resolvers to use for the title
* @since 7.0.0
*/
protected PlotInventory(PlotPlayer<P> player, int size, Caption titleCaption, TagResolver... titleResolvers) {
this.player = player;
this.size = size;
this.titleCaption = titleCaption;
this.titleResolvers = titleResolvers;
}
/**
* Set an item in this inventory at a specific slot / index.
* Overrides existing items and click handler.
*
* @param slot The slot / index where to place the item
* @param item The item to add to this inventory
* @param onClick The handler to call when clicking this item
* @since TODO
*/
public abstract void setItem(int slot, PlotItemStack item, PlotInventoryClickHandler onClick);
/**
* Set an item in this inventory at a specific slot / index.
* Overrides existing items and click handler.
*
* @param slot The slot / index where to place the item
* @param item The item to add to this inventory
* @since TODO
*/
public void setItem(int slot, PlotItemStack item) {
setItem(slot, item, NOOP_CLICK_HANDLER);
}
/**
* Add an item to this inventory, at the first slot possible (first empty slot, or first slot with the exact same item)
*
* @param item The item to add to this inventory
* @param onClick The handler to call when clicking this item
* @since TODO
*/
public abstract void addItem(PlotItemStack item, PlotInventoryClickHandler onClick);
/**
* Add an item to this inventory, at the first slot possible (first empty slot, or first slot with the exact same item)
*
* @param item The item to add to this inventory
* @since TODO
*/
public void addItem(PlotItemStack item) {
addItem(item, NOOP_CLICK_HANDLER);
}
/**
* Opens this inventory
*
* @since TODO
*/
public abstract void open();
/**
* Close this inventory
*
* @since TODO
*/
public abstract void close();
public abstract I toPlatformItem(PlotItemStack item);
/**
* @return the size of this inventory (must be a multiple of 9)
* @since TODO
*/
public int size() {
return size;
}
/**
* Get the associated player of this inventory
* @return {@link PlotPlayer}
*/
public PlotPlayer<P> player() {
return player;
}
protected Caption titleCaption() {
return titleCaption;
}
protected TagResolver[] titleResolvers() {
return titleResolvers;
}
}

View File

@ -0,0 +1,34 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util.gui;
import com.plotsquared.core.plot.PlotItemStack;
public interface PlotInventoryClickHandler {
void handle(PlotItemStack itemStack, PlotInventoryClickType clickType);
}

View File

@ -0,0 +1,37 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util.gui;
public enum PlotInventoryClickType {
LEFT,
SHIFT_LEFT,
RIGHT,
SHIFT_RIGHT,
MIDDLE,
OTHER
}

View File

@ -0,0 +1,50 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util.gui;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.player.PlotPlayer;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
/**
* Provider for creating a {@link PlotInventory}
*
* @param <P> The platform player
* @param <I> The platform item
*/
public interface PlotInventoryProvider<P, I> {
/**
* Creates a new {@link PlotInventory} based on the passed data for the current platform.
*
* @param size The size of the inventory (must be a multiple of 9)
* @param titleCaption The title for the inventory
* @param titleResolvers The (optional) placeholder resolvers for the inventory
* @return The platform inventory
*/
PlotInventory<P, I> createInventory(PlotPlayer<?> player, int size, Caption titleCaption, TagResolver... titleResolvers);
}

View File

@ -18,7 +18,7 @@ plugins {
idea
}
version = "7.0.0-SNAPSHOT"
version = "6.8.2-SNAPSHOT"
allprojects {
group = "com.intellectualsites.plotsquared"