mirror of
https://github.com/xoo0524tw/OpenMBedwars.git
synced 2026-12-05 22:06:02 +02:00
update
This commit is contained in:
1 parent
af0b27c807
commit
0ab0874476
50 files changed
+6322
-3
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
package de.marcely.bedwars.command.admin.tools;
|
||||
|
||||
import de.marcely.bedwars.libraries.com.cryptomorin.xseries.XMaterial;
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import de.marcely.bedwars.tools.ItemBuilder;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.marcely.bedwars.command.BaseCommandHandler;
|
||||
import de.marcely.bedwars.compat.BukkitUtil;
|
||||
import de.marcely.bedwars.message.Message;
|
||||
import de.marcely.bedwars.message.Messages;
|
||||
import de.marcely.bedwars.util.Util;
|
||||
|
||||
public final class ToolsGetPosAxeCommand extends BaseCommandHandler {
|
||||
public void onFire(CommandSender var1, String var2, String[] var3) {
|
||||
Player var4 = (Player)var1;
|
||||
ItemStack var5 = ItemBuilder.of(XMaterial.WOODEN_AXE).name(Util.POSITION_AXE_TITLE).build();
|
||||
BukkitUtil.giveItem(var4, var5);
|
||||
Message.of(Messages.GetPositionAxe).send(var4);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onAutocomplete(CommandSender var1, String[] var2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package de.marcely.bedwars.command.admin.tools;
|
||||
|
||||
import de.marcely.bedwars.api.BedwarsAPI;
|
||||
import de.marcely.bedwars.api.MigrationProcess;
|
||||
import de.marcely.bedwars.api.MigrationProcess.Callback;
|
||||
import de.marcely.bedwars.api.MigrationProcess.Origin;
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import de.marcely.bedwars.command.BaseCommandHandler;
|
||||
import de.marcely.bedwars.message.Message;
|
||||
import de.marcely.bedwars.message.Messages;
|
||||
import de.marcely.bedwars.util.Util;
|
||||
|
||||
public final class ToolsMigrateCommand extends BaseCommandHandler {
|
||||
private final Origin origin;
|
||||
|
||||
public ToolsMigrateCommand(Origin var1) {
|
||||
this.origin = var1;
|
||||
}
|
||||
|
||||
public void onFire(final CommandSender var1, String var2, String[] var3) {
|
||||
final String var4 = this.origin.name().toLowerCase();
|
||||
if (Util.ACTIVE_MIGRATIONS.stream().anyMatch(var1x -> var1x.getOrigin() == this.origin)) {
|
||||
Message.of(Messages.Migration_Failure_AlreadyRunning).send(var1);
|
||||
} else {
|
||||
Message.of(Messages.Migration_Start).withPlaceholder("origin", var4).send(var1);
|
||||
MigrationProcess var5 = BedwarsAPI.prepareMigrationProcess(this.origin);
|
||||
var5.addCallback(new Callback() {
|
||||
public void onSuccess(Duration var1x) {
|
||||
Message.of(Messages.Migration_Success).withPlaceholder("origin", var4).withPlaceholder("time", Math.ceil(var1x.toMillis() / 1000.0) + "s").send(var1);
|
||||
}
|
||||
|
||||
public void onFail(Duration var1x, String var2x) {
|
||||
Message.of(Messages.Migration_Failure).withPlaceholder("origin", var4).withPlaceholder("time", var1x.toMillis() / 1000.0 + "s").withPlaceholder("error", var2x).send(var1);
|
||||
}
|
||||
});
|
||||
var5.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onAutocomplete(CommandSender var1, String[] var2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package de.marcely.bedwars.command.admin.tools;
|
||||
|
||||
import de.marcely.bedwars.core.Registry.PluginEntry;
|
||||
import de.marcely.bedwars.api.command.SubCommand;
|
||||
import de.marcely.bedwars.api.game.shop.ShopOpenCause;
|
||||
import de.marcely.bedwars.api.game.shop.layout.ShopLayout;
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.marcely.bedwars.command.BaseCommandHandler;
|
||||
import de.marcely.bedwars.compat.BukkitUtil;
|
||||
import de.marcely.bedwars.core.Registry;
|
||||
import de.marcely.bedwars.message.Message;
|
||||
import de.marcely.bedwars.message.Messages;
|
||||
import de.marcely.bedwars.shop.Shop;
|
||||
|
||||
public final class ToolsOpenShopCommand extends BaseCommandHandler {
|
||||
private SubCommand subCommand;
|
||||
|
||||
@Override
|
||||
public void onRegister(SubCommand var1) {
|
||||
super.onRegister(var1);
|
||||
this.subCommand = var1;
|
||||
}
|
||||
|
||||
public void onFire(CommandSender var1, String var2, String[] var3) {
|
||||
if (var3.length == 0 && !(var1 instanceof Player)) {
|
||||
Message.of(Messages.Usage).withPlaceholder("usage", this.subCommand.getFullName(this.getBukkitLabel(var2)) + " <player> [layout name]").send(var1);
|
||||
} else {
|
||||
Player var4;
|
||||
if (var3.length == 0) {
|
||||
var4 = (Player)var1;
|
||||
} else {
|
||||
var4 = BukkitUtil.getPlayerByRealName(var3[0]);
|
||||
if (var4 == null) {
|
||||
Message.of(Messages.NotFound_Player).withPlaceholder("player", var3[0]).send(var1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (var3.length <= 1) {
|
||||
Shop.open(var4, ShopOpenCause.COMMAND);
|
||||
} else {
|
||||
Optional var5 = Registry.SHOP_LAYOUT.get(var3[1]);
|
||||
if (!var5.isPresent()) {
|
||||
Message.of(Messages.Unknown_Layout).withPlaceholder("layout", var3[1]).send(var1);
|
||||
} else {
|
||||
Shop.open(var4, (ShopLayout)((PluginEntry)var5.get()).get(), ShopOpenCause.COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onAutocomplete(CommandSender var1, String[] var2) {
|
||||
if (var2.length == 0) {
|
||||
return this.completePlayers();
|
||||
} else if (var2.length == 1) {
|
||||
return this.completePlayers(var2[0]);
|
||||
} else {
|
||||
return var2.length == 2 ? this.completeOptions(var2[1], Registry.SHOP_LAYOUT.getKeys().stream().toArray(String[]::new)) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package de.marcely.bedwars.command.admin.tools;
|
||||
|
||||
import de.marcely.bedwars.core.Registry.PluginEntry;
|
||||
import de.marcely.bedwars.api.command.SubCommand;
|
||||
import de.marcely.bedwars.api.game.upgrade.UpgradeShopOpenCause;
|
||||
import de.marcely.bedwars.api.game.upgrade.layout.UpgradeShopLayout;
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.marcely.bedwars.command.BaseCommandHandler;
|
||||
import de.marcely.bedwars.compat.BukkitUtil;
|
||||
import de.marcely.bedwars.core.Registry;
|
||||
import de.marcely.bedwars.message.Message;
|
||||
import de.marcely.bedwars.message.Messages;
|
||||
import de.marcely.bedwars.shop.upgrade.UpgradeShop;
|
||||
|
||||
public final class ToolsOpenUpgradeShopCommand extends BaseCommandHandler {
|
||||
private SubCommand subCommand;
|
||||
|
||||
@Override
|
||||
public void onRegister(SubCommand var1) {
|
||||
super.onRegister(var1);
|
||||
this.subCommand = var1;
|
||||
}
|
||||
|
||||
public void onFire(CommandSender var1, String var2, String[] var3) {
|
||||
if (var3.length == 0 && !(var1 instanceof Player)) {
|
||||
Message.of(Messages.Usage).withPlaceholder("usage", this.subCommand.getFullName(this.getBukkitLabel(var2)) + " <player> [layout name]").send(var1);
|
||||
} else {
|
||||
Player var4;
|
||||
if (var3.length == 0) {
|
||||
var4 = (Player)var1;
|
||||
} else {
|
||||
var4 = BukkitUtil.getPlayerByRealName(var3[0]);
|
||||
if (var4 == null) {
|
||||
Message.of(Messages.NotFound_Player).withPlaceholder("player", var3[0]).send(var1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (var3.length <= 1) {
|
||||
UpgradeShop.open(var4, UpgradeShopOpenCause.COMMAND);
|
||||
} else {
|
||||
Optional var5 = Registry.UPGRADE_SHOP_LAYOUT.get(var3[1]);
|
||||
if (!var5.isPresent()) {
|
||||
Message.of(Messages.Unknown_Layout).withPlaceholder("layout", var3[1]).send(var1);
|
||||
} else {
|
||||
UpgradeShop.open(var4, (UpgradeShopLayout)((PluginEntry)var5.get()).get(), UpgradeShopOpenCause.COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onAutocomplete(CommandSender var1, String[] var2) {
|
||||
if (var2.length == 0) {
|
||||
return this.completePlayers();
|
||||
} else if (var2.length == 1) {
|
||||
return this.completePlayers(var2[0]);
|
||||
} else {
|
||||
return var2.length == 2 ? this.completeOptions(var2[1], Registry.UPGRADE_SHOP_LAYOUT.getKeys().stream().toArray(String[]::new)) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package de.marcely.bedwars.command.admin.tools;
|
||||
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import de.marcely.bedwars.command.BaseCommandHandler;
|
||||
import de.marcely.bedwars.message.Message;
|
||||
import de.marcely.bedwars.message.Messages;
|
||||
import de.marcely.bedwars.util.Util;
|
||||
|
||||
public final class ToolsRecalcStatsCommand extends BaseCommandHandler {
|
||||
public void onFire(CommandSender var1, String var2, String[] var3) {
|
||||
long var4 = System.currentTimeMillis();
|
||||
Util.updateAllRankings(() -> Message.of(Messages.RecalculateStats_Done).withPlaceholder("time", "" + (System.currentTimeMillis() - var4) / 1000.0).send(var1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onAutocomplete(CommandSender var1, String[] var2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Generated;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ExecutionChain {
|
||||
private final Plugin plugin;
|
||||
private final Queue<Runnable> tasks = new LinkedList<>();
|
||||
private Consumer<Exception> errorHandler;
|
||||
private volatile boolean isRunning;
|
||||
private volatile Runnable cancelListener;
|
||||
|
||||
public ExecutionChain then(Runnable var1) {
|
||||
return this.chain(var1x -> {
|
||||
var1.run();
|
||||
var1x.run();
|
||||
});
|
||||
}
|
||||
|
||||
public ExecutionChain thenThrowing(ThrowingRunnable var1) {
|
||||
return this.chain(var1x -> {
|
||||
var1.run();
|
||||
var1x.run();
|
||||
});
|
||||
}
|
||||
|
||||
public <T> ExecutionChain thenConsumer(ThrowingConsumer<Consumer<T>> var1, ThrowingConsumer<T> var2) {
|
||||
return this.chain(var3 -> var1.accept((Consumer<T>)var3x -> {
|
||||
try {
|
||||
var2.accept(var3x);
|
||||
var3.run();
|
||||
} catch (Exception var5) {
|
||||
this.handle(var5);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public ExecutionChain thenLoose(ThrowingBiConsumer<Runnable, Consumer<Exception>> var1) {
|
||||
AtomicBoolean var2 = new AtomicBoolean(false);
|
||||
return this.chain(var3 -> var1.accept((Runnable)() -> {
|
||||
if (!var2.getAndSet(true)) {
|
||||
var3.run();
|
||||
}
|
||||
}, (Consumer<Exception>)var2xx -> {
|
||||
if (!var2.getAndSet(true)) {
|
||||
this.handle(var2xx);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public ExecutionChain sync() {
|
||||
return this.chain(var0 -> Helper.get().synchronize(var0));
|
||||
}
|
||||
|
||||
public ExecutionChain syncLater(long var1) {
|
||||
return this.chain(var3 -> Bukkit.getScheduler().runTaskLater(this.plugin, var3, var1));
|
||||
}
|
||||
|
||||
public ExecutionChain async() {
|
||||
return this.chain(var1 -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin, var1));
|
||||
}
|
||||
|
||||
public ExecutionChain asyncLater(long var1) {
|
||||
return this.chain(var3 -> Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, var3, var1));
|
||||
}
|
||||
|
||||
public ExecutionChain error(Consumer<Exception> var1) {
|
||||
if (this.errorHandler != null) {
|
||||
throw new IllegalStateException("Error handler already set");
|
||||
}
|
||||
|
||||
this.errorHandler = var1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExecutionChain run() {
|
||||
if (this.isRunning) {
|
||||
throw new IllegalStateException("Chain is already running");
|
||||
} else {
|
||||
this.isRunning = true;
|
||||
Runnable var1 = this.tasks.poll();
|
||||
if (var1 != null) {
|
||||
var1.run();
|
||||
return this;
|
||||
} else {
|
||||
throw new IllegalStateException("No tasks added");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
this.isRunning = false;
|
||||
}
|
||||
|
||||
public void cancel(Runnable var1) {
|
||||
this.cancelListener = var1;
|
||||
this.isRunning = false;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return this.isRunning;
|
||||
}
|
||||
|
||||
protected ExecutionChain chain(ThrowingConsumer<Runnable> var1) {
|
||||
this.tasks.add(() -> {
|
||||
if (!this.isRunning) {
|
||||
this.onEnd();
|
||||
} else {
|
||||
try {
|
||||
var1.accept((Runnable)() -> {
|
||||
Runnable var1xx = this.tasks.poll();
|
||||
if (var1xx != null) {
|
||||
var1xx.run();
|
||||
} else {
|
||||
this.onEnd();
|
||||
}
|
||||
});
|
||||
} catch (Exception var3) {
|
||||
this.handle(var3);
|
||||
}
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
private void onEnd() {
|
||||
this.isRunning = false;
|
||||
if (this.cancelListener != null) {
|
||||
this.cancelListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
protected void handle(Exception var1) {
|
||||
if (this.errorHandler != null) {
|
||||
this.errorHandler.accept(var1);
|
||||
} else {
|
||||
var1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ExecutionChain init(Plugin var0) {
|
||||
return new ExecutionChain(var0);
|
||||
}
|
||||
|
||||
@Generated
|
||||
private ExecutionChain(Plugin var1) {
|
||||
this.plugin = var1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LazyReference<T> implements Supplier<T> {
|
||||
private final Supplier<T> factory;
|
||||
private T cached;
|
||||
|
||||
public LazyReference(Supplier<T> var1) {
|
||||
this.factory = var1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
if (this.cached != null) {
|
||||
return this.cached;
|
||||
} else {
|
||||
this.cached = this.factory.get();
|
||||
if (this.cached == null) {
|
||||
throw new IllegalStateException("Factory may not return null");
|
||||
} else {
|
||||
return this.cached;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.cached = null;
|
||||
}
|
||||
|
||||
public boolean isCached() {
|
||||
return this.cached != null;
|
||||
}
|
||||
|
||||
public static <T> Supplier<T> of(Supplier<T> var0) {
|
||||
return new LazyReference<>(var0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingBiConsumer<T, U> {
|
||||
void accept(T var1, U var2) throws Exception;
|
||||
|
||||
default ThrowingBiConsumer<T, U> andThen(ThrowingBiConsumer<? super T, ? super U> var1) {
|
||||
Objects.requireNonNull(var1);
|
||||
return (var2, var3) -> {
|
||||
this.accept(var2, var3);
|
||||
var1.accept(var2, var3);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingConsumer<T> {
|
||||
void accept(T var1) throws Exception;
|
||||
|
||||
default ThrowingConsumer<T> andThen(ThrowingConsumer<? super T> var1) {
|
||||
Objects.requireNonNull(var1);
|
||||
return var2 -> {
|
||||
this.accept(var2);
|
||||
var1.accept(var2);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingRunnable {
|
||||
void run() throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ThrowingSupplier<T> {
|
||||
T get() throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package de.marcely.bedwars.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class YamlConfigurationDescriptor extends YamlConfiguration {
|
||||
private final List<String> comments = new ArrayList<>();
|
||||
private int emptyLineIndex = 0;
|
||||
|
||||
public void addComment(String var1) {
|
||||
Validate.notNull(var1, "comment");
|
||||
this.comments.add(var1);
|
||||
this.set("@@@TMP_DESCRIPTOR_COMMENT" + this.comments.size(), "tmp");
|
||||
}
|
||||
|
||||
public void addEmptyLine() {
|
||||
this.set("@@@TMP_DESCRIPTOR_EMPTYLINE" + ++this.emptyLineIndex, "tmp");
|
||||
}
|
||||
|
||||
public void addEmptyLine(ConfigurationSection var1) {
|
||||
var1.set("@@@TMP_DESCRIPTOR_EMPTYLINE" + ++this.emptyLineIndex, "tmp");
|
||||
}
|
||||
|
||||
public String saveToString() {
|
||||
String var1 = super.saveToString();
|
||||
|
||||
for (int var2 = 0; var2 < this.comments.size(); var2++) {
|
||||
String var3 = this.comments.get(var2);
|
||||
String var4 = "#";
|
||||
if (var3.length() >= 1 && var3.charAt(0) != '#') {
|
||||
var4 = var4 + " " + var3;
|
||||
} else {
|
||||
var4 = var4 + var3;
|
||||
}
|
||||
|
||||
var1 = StringUtils.replaceOnce(var1, "'@@@TMP_DESCRIPTOR_COMMENT" + (var2 + 1) + "': tmp", var4);
|
||||
}
|
||||
|
||||
for (int var5 = 0; var5 < this.emptyLineIndex; var5++) {
|
||||
var1 = StringUtils.replaceOnce(var1, "'@@@TMP_DESCRIPTOR_EMPTYLINE" + (var5 + 1) + "': tmp", "");
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package de.marcely.bedwars.tools.gui;
|
||||
|
||||
import de.marcely.bedwars.api.message.Message;
|
||||
import de.marcely.bedwars.api.unsafe.BedwarsAPILayer;
|
||||
import de.marcely.bedwars.libraries.org.jetbrains.annotations.Nullable;
|
||||
import de.marcely.bedwars.tools.ItemBuilder;
|
||||
import de.marcely.bedwars.tools.Validate;
|
||||
import de.marcely.bedwars.tools.gui.type.ChestGUI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ScrollableItems {
|
||||
private static final Consumer<Player> DEF_PAGE_CHANGE = var0 -> BedwarsAPILayer.INSTANCE.playSetupGuiClickSwitchSound(var0);
|
||||
private final ChestGUI gui;
|
||||
private final int minX;
|
||||
private final int maxX;
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final int size;
|
||||
private final List<GUIItem> items = new ArrayList<>();
|
||||
private boolean autoRedraw = false;
|
||||
private GUIItem prevPageItem;
|
||||
private GUIItem nextPageItem;
|
||||
private int currentPage;
|
||||
private Consumer<Player> pageChangeListener = DEF_PAGE_CHANGE;
|
||||
|
||||
public ScrollableItems(ChestGUI var1, int var2, int var3, int var4, int var5) {
|
||||
Validate.notNull(var1, "gui");
|
||||
Validate.isTrue(var2 >= 0, "minX must be >= 0");
|
||||
Validate.isTrue(var4 >= 0, "minY must be >= 0");
|
||||
Validate.isTrue(var3 <= 8, "maxX must be <= 8");
|
||||
Validate.isTrue(var5 <= 5, "maxY must be <= 5");
|
||||
Validate.isTrue(var2 <= var3, "minX must be <= maxX");
|
||||
Validate.isTrue(var4 <= var5, "minY must be <= maxY");
|
||||
this.gui = var1;
|
||||
this.minX = var2;
|
||||
this.maxX = var3;
|
||||
this.minY = var4;
|
||||
this.maxY = var5;
|
||||
this.size = (var3 - var2 + 1) * (var5 - var4 + 1);
|
||||
Validate.isTrue(this.size > 2, "The defined area must be big enough to at least show one item and the page change buttons");
|
||||
}
|
||||
|
||||
public void addItem(GUIItem var1) {
|
||||
Validate.notNull(var1, "item");
|
||||
this.items.add(var1);
|
||||
this.attemptDraw();
|
||||
}
|
||||
|
||||
public void setItems(List<GUIItem> var1) {
|
||||
Validate.notNull(var1, "items");
|
||||
this.items.clear();
|
||||
this.items.addAll(var1);
|
||||
this.attemptDraw();
|
||||
}
|
||||
|
||||
public List<GUIItem> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public int getMaxPages() {
|
||||
int var1 = this.items.size();
|
||||
return var1 == 0 ? 1 : Math.max(1, (var1 + this.size - 5) / (this.size - 2));
|
||||
}
|
||||
|
||||
public void setCurrentPage(int var1) {
|
||||
var1 = Math.max(Math.min(var1, this.getMaxPages() - 1), 0);
|
||||
if (this.currentPage != var1) {
|
||||
this.currentPage = var1;
|
||||
this.attemptDraw();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return this.currentPage;
|
||||
}
|
||||
|
||||
public void setPrevPageItem(ItemStack var1) {
|
||||
Validate.notNull(var1, "is");
|
||||
this.prevPageItem = new GUIItem(var1, (var1x, var2, var3) -> {
|
||||
this.setCurrentPage(this.currentPage - 1);
|
||||
if (this.pageChangeListener != null) {
|
||||
this.pageChangeListener.accept(var1x);
|
||||
}
|
||||
});
|
||||
this.attemptDraw();
|
||||
}
|
||||
|
||||
public void setNextPageItem(ItemStack var1) {
|
||||
Validate.notNull(var1, "is");
|
||||
this.nextPageItem = new GUIItem(var1, (var1x, var2, var3) -> {
|
||||
this.setCurrentPage(this.currentPage + 1);
|
||||
if (this.pageChangeListener != null) {
|
||||
this.pageChangeListener.accept(var1x);
|
||||
}
|
||||
});
|
||||
this.attemptDraw();
|
||||
}
|
||||
|
||||
public void setPageChangeListener(@Nullable Consumer<Player> var1) {
|
||||
this.pageChangeListener = var1;
|
||||
}
|
||||
|
||||
public void setDefaultPageChangeItems(@Nullable Player var1) {
|
||||
this.setPrevPageItem(ItemBuilder.of(Material.ARROW).name(ChatColor.WHITE + Message.buildByKey("SetupGUI_PrevPage").done(var1)).build());
|
||||
this.setNextPageItem(ItemBuilder.of(Material.ARROW).name(ChatColor.WHITE + Message.buildByKey("SetupGUI_NextPage").done(var1)).build());
|
||||
}
|
||||
|
||||
private void attemptDraw() {
|
||||
if (this.autoRedraw) {
|
||||
this.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
MutableInt var1 = new MutableInt(this.minX);
|
||||
MutableInt var2 = new MutableInt(this.minY);
|
||||
Consumer<GUIItem> var3 = var3x -> {
|
||||
this.gui.setItem(var3x, var1.intValue(), var2.intValue());
|
||||
var1.increment();
|
||||
if (var1.intValue() > this.maxX) {
|
||||
var1.setValue(this.minX);
|
||||
var2.increment();
|
||||
}
|
||||
};
|
||||
if (this.nextPageItem != null && this.prevPageItem != null) {
|
||||
if (this.currentPage > 0) {
|
||||
var3.accept(this.prevPageItem);
|
||||
}
|
||||
|
||||
int var4 = this.getMaxPages();
|
||||
boolean var5 = var4 > this.currentPage + 1;
|
||||
int var6 = this.currentPage * (this.size - 1) - Math.max(0, this.currentPage - 1);
|
||||
boolean var7 = false;
|
||||
|
||||
for (int var8 = var6; var8 < this.items.size(); var8++) {
|
||||
var7 = var1.intValue() == this.maxX && var2.intValue() == this.maxY;
|
||||
if (var5 && var7) {
|
||||
break;
|
||||
}
|
||||
|
||||
var3.accept(this.items.get(var8));
|
||||
if (var7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (var5) {
|
||||
var3.accept(this.nextPageItem);
|
||||
} else if (!var7) {
|
||||
do {
|
||||
var7 = var1.intValue() == this.maxX && var2.intValue() == this.maxY;
|
||||
var3.accept(null);
|
||||
} while (!var7);
|
||||
}
|
||||
|
||||
this.autoRedraw = true;
|
||||
} else {
|
||||
throw new IllegalStateException("Missing prev / next page items");
|
||||
}
|
||||
}
|
||||
|
||||
public void disableRedraw() {
|
||||
this.autoRedraw = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package de.marcely.bedwars.tools.location;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class ImmutableXYZ extends XYZ {
|
||||
public ImmutableXYZ() {
|
||||
super(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
public ImmutableXYZ(Location var1) {
|
||||
super(var1.getX(), var1.getY(), var1.getZ());
|
||||
}
|
||||
|
||||
public ImmutableXYZ(Vector var1) {
|
||||
super(var1.getX(), var1.getY(), var1.getZ());
|
||||
}
|
||||
|
||||
public ImmutableXYZ(XYZ var1) {
|
||||
this(var1.getX(), var1.getY(), var1.getZ());
|
||||
}
|
||||
|
||||
public ImmutableXYZ(double var1, double var3, double var5) {
|
||||
super(var1, var3, var5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ setX(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ setY(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ setZ(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ set(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ set(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ set(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ add(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ add(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ add(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ add(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ subtract(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ subtract(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ subtract(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ subtract(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ multiply(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ multiply(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZ zero() {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package de.marcely.bedwars.tools.location;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class ImmutableXYZD extends XYZD {
|
||||
public ImmutableXYZD(Location var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZD(Vector var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZD(XYZ var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZD(XYZD var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZD() {
|
||||
}
|
||||
|
||||
public ImmutableXYZD(double var1, double var3, double var5) {
|
||||
super(var1, var3, var5);
|
||||
}
|
||||
|
||||
public ImmutableXYZD(double var1, double var3, double var5, XYZD.Direction var7) {
|
||||
super(var1, var3, var5, var7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD setX(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD setY(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD setZ(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD set(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD set(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD set(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD add(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD add(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD add(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD add(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD subtract(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD subtract(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD subtract(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD subtract(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD multiply(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD multiply(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD zero() {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZD setDirection(XYZD.Direction var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package de.marcely.bedwars.tools.location;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class ImmutableXYZYP extends XYZYP {
|
||||
public ImmutableXYZYP(Location var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZYP(Vector var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZYP(XYZ var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZYP(XYZYP var1) {
|
||||
super(var1);
|
||||
}
|
||||
|
||||
public ImmutableXYZYP() {
|
||||
}
|
||||
|
||||
public ImmutableXYZYP(double var1, double var3, double var5) {
|
||||
super(var1, var3, var5);
|
||||
}
|
||||
|
||||
public ImmutableXYZYP(double var1, double var3, double var5, float var7, float var8) {
|
||||
super(var1, var3, var5, var7, var8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP setX(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP setY(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP setZ(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP set(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP set(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP set(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP add(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP add(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP add(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP add(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP subtract(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP subtract(XYZ var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP subtract(Location var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP subtract(Vector var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP multiply(double var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP multiply(double var1, double var3, double var5) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP zero() {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP setYaw(float var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XYZYP setPitch(float var1) {
|
||||
throw new UnsupportedOperationException("Trying to modify an immutable object");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user