Little cleanup & setup (#4)

* Setup project

* Update namespace

- Relocate bstats

* Some reformatting and documentation

* Setup issue templates

* chmod+x gradlew

* Create pull request template

* Apply license

* Exclude XMaterial from licensing
This commit is contained in:
NotMyFault authored and GitHub committed 2020-09-08 20:59:30 +02:00
1 parent f763d4c472
commit 9806a083bc
129 files changed
+5068 -1506

No files matched your search

@@ -0,0 +1,145 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities;
import net.arcaniax.buildersutilities.commands.system.CommandForwarder;
import net.arcaniax.buildersutilities.listeners.*;
import net.arcaniax.buildersutilities.menus.inv.InventoryManager;
import net.arcaniax.buildersutilities.utils.CustomConfig;
import net.arcaniax.buildersutilities.utils.NmsManager;
import net.arcaniax.buildersutilities.utils.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin {
public static final String MSG_PREFIX = ChatColor.DARK_AQUA + "BuildersUtils> " + ChatColor.AQUA;
public static final String MSG_ERROR = ChatColor.DARK_RED + "Error: " + ChatColor.RED;
private Metrics metrics;
private static Main instance;
private Settings settings;
private NoClipManager noClipManager;
private InventoryManager inventoryManager;
private NmsManager nmsManager;
public static Main getInstance() {
return instance;
}
@Override
public void onEnable() {
instance = this;
this.settings = new Settings(new CustomConfig(this, "config.yml"));
this.noClipManager = new NoClipManager();
this.nmsManager = new NmsManager();
this.inventoryManager = new InventoryManager(this);
this.inventoryManager.init();
this.metrics = new Metrics(this, 5168);
this.getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
this.getServer().getPluginManager().registerEvents(new BlockPhysicsListener(), this);
this.getServer().getPluginManager().registerEvents(new ExplosionListener(), this);
this.getServer().getPluginManager().registerEvents(new IronTrapdoorListener(), this);
this.getServer().getPluginManager().registerEvents(new LeafDecayListener(), this);
this.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
this.getServer().getPluginManager().registerEvents(new PlayerMoveListener(), this);
this.getServer().getPluginManager().registerEvents(new PlayerQuitAndJoinListener(), this);
this.getServer().getPluginManager().registerEvents(new TeleportListener(), this);
this.getServer().getPluginManager().registerEvents(new TerracottaInteractListener(), this);
this.getServer().getPluginManager().registerEvents(new WeatherChangeListener(), this);
CommandForwarder executor = new CommandForwarder();
this.getCommand("bu").setExecutor(executor);
this.getCommand("buildersutils").setExecutor(executor);
this.getCommand("builders").setExecutor(executor);
this.getCommand("utils").setExecutor(executor);
this.getCommand("util").setExecutor(executor);
CommandExecutor commandExecutor = new CommandExecutor() {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s,
String[] strings) {
String[] commandArgs = new String[strings.length + 1];
commandArgs[0] = s;
System.arraycopy(strings, 0, commandArgs, 1, strings.length);
executor.onCommand(commandSender, command, s, commandArgs);
return true;
}
};
getCommand("banner").setExecutor(commandExecutor);
getCommand("armorcolor").setExecutor(commandExecutor);
getCommand("blocks").setExecutor(commandExecutor);
getCommand("n").setExecutor(commandExecutor);
getCommand("nc").setExecutor(commandExecutor);
getCommand("/1").setExecutor(commandExecutor);
getCommand("/2").setExecutor(commandExecutor);
getCommand("/cuboid").setExecutor(commandExecutor);
getCommand("/convex").setExecutor(commandExecutor);
getCommand("/s").setExecutor(commandExecutor);
getCommand("/r").setExecutor(commandExecutor);
getCommand("/f").setExecutor(commandExecutor);
getCommand("/pa").setExecutor(commandExecutor);
getCommand("/c").setExecutor(commandExecutor);
getCommand("ws").setExecutor(commandExecutor);
getCommand("fs").setExecutor(commandExecutor);
getCommand("af").setExecutor(commandExecutor);
getCommand("advfly").setExecutor(commandExecutor);
getCommand("/derot").setExecutor(commandExecutor);
getCommand("/scale").setExecutor(commandExecutor);
getCommand("/twist").setExecutor(commandExecutor);
getCommand("butil").setExecutor(commandExecutor);
}
private void startMetrics() {
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
public Settings getSettings() {
return settings;
}
public NoClipManager getNoClipManager() {
return noClipManager;
}
public InventoryManager getInventoryManager() {
return inventoryManager;
}
public NmsManager getNmsManager() {
return nmsManager;
}
}
@@ -0,0 +1,98 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class NoClipManager {
public static Set<UUID> noClipPlayerIds;
public NoClipManager() {
noClipPlayerIds = new HashSet<>();
Bukkit.getScheduler().runTaskTimer(Main.getInstance(), this::checkForBlocks, 1L, 1L);
}
private void checkForBlocks() {
for (UUID name : noClipPlayerIds) {
Player player = Bukkit.getPlayer(name);
if (player != null && player.isOnline()) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
boolean noClip;
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR && player
.isSneaking()) {
noClip = true;
} else {
noClip = isNoClip(player);
}
if (noClip) {
player.setGameMode(GameMode.SPECTATOR);
}
} else if (player.getGameMode().equals(GameMode.SPECTATOR)) {
boolean noClip;
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR) {
noClip = true;
} else {
noClip = isNoClip(player);
}
if (!noClip) {
player.setGameMode(GameMode.CREATIVE);
}
}
}
}
}
private boolean isNoClip(Player player) {
boolean noClip = false;
if (player.getLocation().add(+0.4, 0, 0).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(-0.4, 0, 0).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(0, 0, +0.4).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(0, 0, -0.4).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(+0.4, 1, 0).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(-0.4, 1, 0).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(0, 1, +0.4).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(0, 1, -0.4).getBlock().getType() != Material.AIR) {
noClip = true;
} else if (player.getLocation().add(0, +1.9, 0).getBlock().getType() != Material.AIR) {
noClip = true;
}
return noClip;
}
}
@@ -0,0 +1,61 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities;
import net.arcaniax.buildersutilities.utils.CustomConfig;
public class Settings {
public static boolean disableWeatherChanges;
public static boolean disableRedstone;
public static boolean disablePhysics;
public static boolean disableGravityPhysics;
public static boolean disableExplosions;
public static boolean disableSoilTrample;
public static boolean disableLeavesDecay;
public static boolean fixAttackSpeed;
public static boolean preventDragonEggTeleport;
public static boolean sendErrorMessages;
private final CustomConfig customConfig;
public Settings(CustomConfig customConfig) {
this.customConfig = customConfig;
reloadSettings();
}
public void reloadSettings() {
disableWeatherChanges = customConfig.get("disable-weather-changes", Boolean.class, true);
disableRedstone = customConfig.get("disable-redstone", Boolean.class, false);
disablePhysics = customConfig.get("disable-physics", Boolean.class, true);
disableGravityPhysics = customConfig.get("disable-gravity-physics", Boolean.class, false);
disableExplosions = customConfig.get("disable-explosions", Boolean.class, true);
disableSoilTrample = customConfig.get("disable-soil-trample", Boolean.class, true);
disableLeavesDecay = customConfig.get("disable-leaves-decay", Boolean.class, true);
fixAttackSpeed = customConfig.get("fix-attackspeed", Boolean.class, false);
preventDragonEggTeleport = customConfig.get("prevent-dragon-egg-teleport", Boolean.class, true);
sendErrorMessages = customConfig.get("send-error-messages", Boolean.class, true);
}
}
@@ -0,0 +1,50 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import net.arcaniax.buildersutilities.listeners.PlayerMoveListener;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class AdvancedFlyCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.advancedfly")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (PlayerMoveListener.togglePlayer(player)) {
player.sendMessage(Main.MSG_PREFIX + "Advanced Fly " + ChatColor.GREEN + ChatColor.ITALIC + "Enabled");
} else {
player.sendMessage(Main.MSG_PREFIX + "Advanced Fly " + ChatColor.RED + ChatColor.ITALIC + "Disabled");
}
}
}
@@ -0,0 +1,47 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import net.arcaniax.buildersutilities.menus.Menus;
import org.bukkit.entity.Player;
public class BannerCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.banner")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Menus.BANNER_MENU.open(player);
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import net.arcaniax.buildersutilities.menus.Menus;
import org.bukkit.entity.Player;
public class ColorCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.color")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Menus.COLOR_MENU.open(player);
}
}
@@ -0,0 +1,43 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class HelpCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.help")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
}
}
}
@@ -0,0 +1,53 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class NightVisionCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.nightvision")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
player.sendMessage(Main.MSG_PREFIX + "Night Vision " + ChatColor.RED + ChatColor.ITALIC + "Disabled");
} else {
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, true, false));
player.sendMessage(Main.MSG_PREFIX + "Night Vision " + ChatColor.GREEN + ChatColor.ITALIC + "Enabled");
}
}
}
@@ -0,0 +1,56 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.NoClipManager;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
public class NoClipCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.noclip")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (NoClipManager.noClipPlayerIds.contains(player.getUniqueId())) {
NoClipManager.noClipPlayerIds.remove(player.getUniqueId());
player.sendMessage(Main.MSG_PREFIX + "NoClip " + ChatColor.RED + ChatColor.ITALIC + "Disabled");
if (player.getGameMode() == GameMode.SPECTATOR) {
player.setGameMode(GameMode.CREATIVE);
}
} else {
NoClipManager.noClipPlayerIds.add(player.getUniqueId());
player.sendMessage(Main.MSG_PREFIX + "NoClip " + ChatColor.GREEN + ChatColor.ITALIC + "Enabled");
}
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import net.arcaniax.buildersutilities.menus.Menus;
import org.bukkit.entity.Player;
public class SecretBlockCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.secretblocks")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Menus.SECRET_BLOCK_MENU.open(player);
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import net.arcaniax.buildersutilities.menus.Menus;
import org.bukkit.entity.Player;
public class UtilsCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.gui")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Menus.TOGGLE_MENU.open(player);
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class ConvexSelectionAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Main.getInstance().getServer().dispatchCommand(player, "/sel convex");
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class CopyAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "/copy " + builder.toString());
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class CuboidSelectionAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Main.getInstance().getServer().dispatchCommand(player, "/sel cuboid");
}
}
@@ -0,0 +1,73 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class DeformRotateAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (args.length != 2) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//derot [axis] [degrees]");
return;
}
int degrees;
try {
degrees = Integer.parseInt(args[1]);
} catch (Exception e) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//derot [axis] [degrees]");
return;
}
// Old:
// float radian = (float) (((float) degrees / (float) 360) * 2 * Math.PI);
//Use the degree to radian conversion number: "0.0174533" radians per degree
float radiansPerDegree = 0.0174533f;
float radian = degrees * radiansPerDegree;
if (args[0].equalsIgnoreCase("x")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(y,z," + radian + ")");
} else if (args[0].equalsIgnoreCase("y")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(x,z," + radian + ")");
} else if (args[0].equalsIgnoreCase("z")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(x,y," + radian + ")");
} else {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//derot [axis] [degrees]");
}
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class FlipAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "/flip " + builder.toString());
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class FlySpeedAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "speed fly " + builder.toString());
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class PasteAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "/paste " + builder.toString());
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class PosOneAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Main.getInstance().getServer().dispatchCommand(player, "/pos1");
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class PosTwoAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
Main.getInstance().getServer().dispatchCommand(player, "/pos2");
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class ReplaceAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "/replace " + builder.toString());
}
}
@@ -0,0 +1,58 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class ScaleAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (args.length != 1) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//scale [size]");
return;
}
double size;
try {
size = Double.parseDouble(args[0]);
} catch (Exception e) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//scale [size]");
return;
}
Main.getInstance().getServer().dispatchCommand(player, "/deform x/=" + size + ";y/=" + size + ";z/=" + size);
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class SetAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "/set " + builder.toString());
}
}
@@ -0,0 +1,70 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class TwistAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
if (args.length != 2) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//twist [axis] [degrees]");
return;
}
int degrees;
try {
degrees = Integer.parseInt(args[1]);
} catch (Exception e) {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//twist [axis] [degrees]");
return;
}
float radiansPerDegree = 0.0174533f;
float radian = degrees * radiansPerDegree;
if (args[0].equalsIgnoreCase("x")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(y,z," + radian / 2 + "*(x+1))");
} else if (args[0].equalsIgnoreCase("y")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(x,z," + radian / 2 + "*(y+1))");
} else if (args[0].equalsIgnoreCase("z")) {
Main.getInstance().getServer().dispatchCommand(player, "/deform rotate(x,y," + radian / 2 + "*(z+1))");
} else {
player.sendMessage(Main.MSG_PREFIX + ChatColor.RED + "//twist [axis] [degrees]");
}
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.aliases;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.Settings;
import net.arcaniax.buildersutilities.commands.system.ICommand;
import org.bukkit.entity.Player;
public class WalkSpeedAliasCommand implements ICommand {
@Override
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
}
return;
}
StringBuilder builder = new StringBuilder();
if (args.length != 0) {
for (String arg : args) {
builder.append(arg).append(" ");
}
}
Main.getInstance().getServer().dispatchCommand(player, "speed walk " + builder.toString());
}
}
@@ -0,0 +1,114 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.system;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.commands.AdvancedFlyCommand;
import net.arcaniax.buildersutilities.commands.BannerCommand;
import net.arcaniax.buildersutilities.commands.ColorCommand;
import net.arcaniax.buildersutilities.commands.HelpCommand;
import net.arcaniax.buildersutilities.commands.SecretBlockCommand;
import net.arcaniax.buildersutilities.commands.NoClipCommand;
import net.arcaniax.buildersutilities.commands.NightVisionCommand;
import net.arcaniax.buildersutilities.commands.UtilsCommand;
import net.arcaniax.buildersutilities.commands.aliases.ConvexSelectionAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.CuboidSelectionAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.PosOneAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.PosTwoAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.SetAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.ReplaceAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.PasteAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.FlipAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.CopyAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.DeformRotateAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.TwistAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.ScaleAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.WalkSpeedAliasCommand;
import net.arcaniax.buildersutilities.commands.aliases.FlySpeedAliasCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class CommandForwarder implements CommandExecutor {
private final Map<String, ICommand> commands;
public CommandForwarder() {
commands = new HashMap<>();
registerCommand(new HelpCommand(), "help", "h", "?");
registerCommand(new AdvancedFlyCommand(), "af", "advancedfly");
registerCommand(new BannerCommand(), "banner");
registerCommand(new ColorCommand(), "color", "ac", "armorcolor");
registerCommand(new SecretBlockCommand(), "secretblock", "secretblocks", "blocks");
registerCommand(new NoClipCommand(), "noclip", "nc");
registerCommand(new NightVisionCommand(), "nv", "nightvision", "n");
registerCommand(new UtilsCommand(), "utils", "u", "util", "gui", "inventory");
registerCommand(new PosOneAliasCommand(), "p1", "1", "one", "pos1");
registerCommand(new PosTwoAliasCommand(), "p2", "2", "two", "pos2");
registerCommand(new CuboidSelectionAliasCommand(), "cuboid", "cube");
registerCommand(new ConvexSelectionAliasCommand(), "convex", "conv");
registerCommand(new SetAliasCommand(), "set", "s");
registerCommand(new ReplaceAliasCommand(), "replace", "r", "repl", "rep");
registerCommand(new PasteAliasCommand(), "paste", "pa");
registerCommand(new FlipAliasCommand(), "flip", "f");
registerCommand(new CopyAliasCommand(), "copy", "c", "clone");
registerCommand(new DeformRotateAliasCommand(), "deformrotate", "defrot", "dr");
registerCommand(new TwistAliasCommand(), "twist", "tw", "t");
registerCommand(new ScaleAliasCommand(), "scale", "sc");
registerCommand(new WalkSpeedAliasCommand(), "walkspeed", "ws");
registerCommand(new FlySpeedAliasCommand(), "flyspeed", "fs");
}
private void registerCommand(ICommand iCommand, String... aliases) {
for (String alias : aliases) {
commands.put(alias.toLowerCase(), iCommand);
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
//Make it player-only
Player player = sender instanceof Player ? ((Player) sender) : null;
if (player == null) {
sender.sendMessage(Main.MSG_ERROR + "Sorry this command can only be used by a player.");
return false;
}
if (args.length == 0) {
new HelpCommand().execute(player, args);
return true;
}
ICommand iCommand = commands.get(args[0].toLowerCase());
if (iCommand != null) {
iCommand.execute(player, Arrays.copyOfRange(args, 1, args.length));
}
return true;
}
}
@@ -0,0 +1,33 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.commands.system;
import org.bukkit.entity.Player;
public interface ICommand {
void execute(Player player, String[] args);
}
@@ -0,0 +1,93 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.Slab;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class BlockBreakListener implements Listener {
public static Set<UUID> slabIds;
public BlockBreakListener() {
slabIds = new HashSet<>();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent e) {
if (e.isCancelled()) {
return;
}
if (slabIds.contains(e.getPlayer().getUniqueId())) {
return;
}
if (!e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
return;
}
Material type = e.getPlayer().getInventory().getItemInMainHand().getType();
if (type.toString().toLowerCase().contains("slab")) {
if (e.isCancelled()) {
return;
}
if (e.getBlock().getType().toString().toLowerCase().contains("slab")) {
if (isTop(e.getPlayer(), e.getBlock())) {
Slab blockdata = (Slab) e.getBlock().getBlockData();
if (blockdata.getType().equals(Slab.Type.DOUBLE)) {
blockdata.setType(Slab.Type.BOTTOM);
e.getBlock().setBlockData(blockdata, true);
e.setCancelled(true);
}
} else {
Slab blockdata = (Slab) e.getBlock().getBlockData();
if (blockdata.getType().equals(Slab.Type.DOUBLE)) {
blockdata.setType(Slab.Type.TOP);
e.getBlock().setBlockData(blockdata, true);
e.setCancelled(true);
}
}
}
}
}
private boolean isTop(Player player, Block block) {
Location start = player.getEyeLocation().clone();
while ((!start.getBlock().equals(block)) && start.distance(player.getEyeLocation()) < 6) {
start.add(player.getLocation().getDirection().multiply(0.05));
}
return start.getY() % 1 > 0.5;
}
}
@@ -0,0 +1,83 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
public class BlockPhysicsListener implements Listener {
@EventHandler
public void onPhysics(BlockPhysicsEvent e) {
Bukkit.broadcastMessage(e.getSourceBlock().getType().name());
Bukkit.broadcastMessage(e.getChangedType().name());
try {
if (e.getChangedType().name().toLowerCase().contains("chest") ||
e.getChangedType().name().toLowerCase().contains("fence") ||
e.getChangedType().name().toLowerCase().contains("grass_block") ||
e.getChangedType().name().toLowerCase().contains("snow") ||
e.getBlock().getType().name().toLowerCase().contains("snow") ||
e.getBlock().getType().name().toLowerCase().contains("grass_block") ||
e.getChangedType().name().toLowerCase().contains("pane") ||
e.getChangedType().name().toLowerCase().contains("wall") ||
e.getChangedType().name().toLowerCase().contains("bar")) {
return;
}
} catch (Exception ex) {
return;
}
if (!Settings.disableRedstone) {
if (e.getChangedType().name().toLowerCase().contains("redstone") ||
e.getChangedType().name().toLowerCase().contains("daylight") ||
e.getChangedType().name().toLowerCase().contains("diode") ||
e.getChangedType().name().toLowerCase().contains("note") ||
e.getChangedType().name().toLowerCase().contains("lever") ||
e.getChangedType().name().toLowerCase().contains("button") ||
e.getChangedType().name().toLowerCase().contains("command") ||
e.getChangedType().name().toLowerCase().contains("tripwire") ||
e.getChangedType().name().toLowerCase().contains("plate") ||
e.getChangedType().name().toLowerCase().contains("string") ||
e.getChangedType().name().toLowerCase().contains("piston") ||
e.getChangedType().name().toLowerCase().contains("observer")) {
if (!e.getBlock().getType().name().contains("air")) {
return;
}
}
}
if (e.getChangedType().hasGravity()) {
if (Settings.disableGravityPhysics) {
e.setCancelled(true);
}
} else {
if (Settings.disablePhysics) {
e.setCancelled(true);
}
}
}
}
@@ -0,0 +1,41 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
public class ExplosionListener implements Listener {
@EventHandler
public void onExplode(EntityExplodeEvent event) {
if (Settings.disableExplosions) {
event.setCancelled(true);
}
}
}
@@ -0,0 +1,85 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Main;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.TrapDoor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class IronTrapdoorListener implements Listener {
public static Set<UUID> ironTrapdoorIds;
public IronTrapdoorListener() {
ironTrapdoorIds = new HashSet<>();
}
@EventHandler(priority = EventPriority.MONITOR)
public void ironTrapDoorInteract(final PlayerInteractEvent e) {
if (e.isCancelled()) {
return;
}
if (ironTrapdoorIds.contains(e.getPlayer().getUniqueId())) {
return;
}
if (!e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
return;
}
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
return;
}
if (!e.getClickedBlock().getType().equals(Material.IRON_TRAPDOOR)) {
return;
}
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 9, 0)) {
if (!e.getHand().equals(EquipmentSlot.HAND)) {
return;
}
}
if (e.getPlayer().isSneaking()) {
return;
}
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Block b = e.getClickedBlock();
TrapDoor trapDoor = (TrapDoor) b.getBlockData();
trapDoor.setOpen(!trapDoor.isOpen());
b.setBlockData(trapDoor);
}, 0L);
e.setCancelled(true);
}
}
@@ -0,0 +1,40 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.LeavesDecayEvent;
public class LeafDecayListener implements Listener {
@EventHandler
public void onLeafDecay(LeavesDecayEvent event) {
if (Settings.disableLeavesDecay) {
event.setCancelled(true);
}
}
}
@@ -0,0 +1,66 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class PlayerInteractListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onDragonEggTP(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& event.getClickedBlock().getType().equals(Material.DRAGON_EGG)
&& (!event.getPlayer().isSneaking())
&& Settings.preventDragonEggTeleport) {
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
if (Settings.disableSoilTrample) {
if (event.getAction() == Action.PHYSICAL) {
Block block = event.getClickedBlock();
if (block != null && block.getType() == Material.FARMLAND) {
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
event.setCancelled(true);
}
}
}
}
}
@@ -0,0 +1,96 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
import java.util.*;
public class PlayerMoveListener implements Listener {
private static final List<String> slower = new ArrayList<>();
private static final List<String> slower2 = new ArrayList<>();
public static Set<UUID> enabledPlayers = new HashSet<>();
private final HashMap<String, Double> lastVelocity = new HashMap<>();
public static boolean togglePlayer(Player p) {
if (enabledPlayers.contains(p.getUniqueId())) {
enabledPlayers.remove(p.getUniqueId());
return false;
} else {
enabledPlayers.add(p.getUniqueId());
return true;
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onMove(final PlayerMoveEvent e) {
if (e.getPlayer().isFlying()) {
if (!enabledPlayers.contains(e.getPlayer().getUniqueId())) {
return;
}
Double speed = e.getFrom().clone().add(0, -e.getFrom().getY(), 0).distance(e.getTo().clone().add(0, -e.getTo().getY(), 0));
if (Math.abs(e.getFrom().getYaw() - e.getTo().getYaw()) > 5) {
return;
}
if (Math.abs(e.getFrom().getPitch() - e.getTo().getPitch()) > 5) {
return;
}
if (lastVelocity.containsKey(e.getPlayer().getName())) {
Double lastSpeed = lastVelocity.get(e.getPlayer().getName());
if (speed * 1.3 < lastSpeed) {
if (slower.contains(e.getPlayer().getName())) {
if (slower2.contains(e.getPlayer().getName())) {
Vector v = e.getPlayer().getVelocity().clone();
v.setX(0);
v.setZ(0);
e.getPlayer().setVelocity(v);
lastVelocity.put(e.getPlayer().getName(), 0.0);
//No more if slower.contains** as if e.getPlayer().getName() isn't there, it won't get removed (:
slower.remove(e.getPlayer().getName());
slower2.remove(e.getPlayer().getName());
} else {
slower2.add(e.getPlayer().getName());
}
} else {
slower.add(e.getPlayer().getName());
}
} else if (speed > lastSpeed) {
lastVelocity.put(e.getPlayer().getName(), speed);
slower.remove(e.getPlayer().getName());
slower2.remove(e.getPlayer().getName());
}
} else {
lastVelocity.put(e.getPlayer().getName(), speed);
slower.remove(e.getPlayer().getName());
}
}
}
}
@@ -0,0 +1,63 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.NoClipManager;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerQuitAndJoinListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
NoClipManager.noClipPlayerIds.remove(player.getUniqueId());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 9, 0)) {
AttributeInstance attribute = event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED);
if (attribute == null) {
return;
}
if (Settings.fixAttackSpeed) {
attribute.setBaseValue(1024.0D);
} else if (attribute.getBaseValue() == 1024.0D) {
attribute.setBaseValue(attribute.getDefaultValue());
}
event.getPlayer().saveData();
}
}
}
@@ -0,0 +1,45 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;
public class TeleportListener implements Listener {
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.SPECTATE)) {
//TODO what is this tpgm3 lol
if (!event.getPlayer().hasPermission("builders.util.tpgm3")) {
event.setCancelled(true);
}
}
}
}
@@ -0,0 +1,92 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Main;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Directional;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class TerracottaInteractListener implements Listener {
public static Set<UUID> terracottaIds;
public TerracottaInteractListener() {
terracottaIds = new HashSet<>();
}
@EventHandler(priority = EventPriority.MONITOR)
public void GlazedTerracottaInteract(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
if (terracottaIds.contains(event.getPlayer().getUniqueId())) {
return;
}
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
return;
}
if (!event.getHand().equals(EquipmentSlot.HAND)) {
return;
}
if (!event.getClickedBlock().getType().name().contains("GLAZED")) {
return;
}
if (!event.getPlayer().isSneaking()) {
return;
}
Material type = event.getPlayer().getInventory().getItemInHand().getType();
if (!(type.equals(Material.AIR))) {
return;
}
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Block block = event.getClickedBlock();
Directional directional = (Directional) block.getBlockData();
if (directional.getFacing().equals(BlockFace.NORTH)) {
directional.setFacing(BlockFace.EAST);
} else if (directional.getFacing().equals(BlockFace.EAST)) {
directional.setFacing(BlockFace.SOUTH);
} else if (directional.getFacing().equals(BlockFace.SOUTH)) {
directional.setFacing(BlockFace.WEST);
} else if (directional.getFacing().equals(BlockFace.WEST)) {
directional.setFacing(BlockFace.NORTH);
}
block.setBlockData(directional);
}, 0L);
event.setCancelled(true);
}
}
@@ -0,0 +1,39 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.WeatherChangeEvent;
public class WeatherChangeListener implements Listener {
@EventHandler
public void onWeather(WeatherChangeEvent e) {
if (Settings.disableWeatherChanges) {
e.setCancelled(true);
}
}
}
@@ -0,0 +1,36 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import org.bukkit.entity.Player;
public class BannerMenuProvider implements InventoryProvider {
@Override
public void init(Player player, InventoryContents contents) {
}
}
@@ -0,0 +1,157 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.concurrent.ThreadLocalRandom;
public class ColorMenuProvider implements InventoryProvider {
private static final float MULTIPLIER = 255f / 20f;
private static final String LORE = "&7__&7Left click to increase__&7Right click to decrease__&7Shift click to change by 5";
@Override
public void init(Player player, InventoryContents contents) {
setRedItem(player, contents, 10);
setRedRandomItem(player, contents);
setGreenItem(player, contents, 10);
setGreenRandomItem(player, contents);
setBlueItem(player, contents, 10);
setBlueRandomItem(player, contents);
setLeatherItems(player, contents);
}
private void setLeatherItems(Player player, InventoryContents contents) {
int r;
if (contents.get(3, 4).get().getItem().getType().equals(Material.RED_STAINED_GLASS)) {
r = 0;
} else {
r = (int) (contents.get(3, 4).get().getItem().getAmount() * MULTIPLIER);
}
int g;
if (contents.get(3, 5).get().getItem().getType().equals(Material.GREEN_STAINED_GLASS)) {
g = 0;
} else {
g = (int) (contents.get(3, 5).get().getItem().getAmount() * MULTIPLIER);
}
int b;
if (contents.get(3, 6).get().getItem().getType().equals(Material.BLUE_STAINED_GLASS)) {
b = 0;
} else {
b = (int) (contents.get(3, 6).get().getItem().getAmount() * MULTIPLIER);
}
contents.set(1, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_HELMET), r, g, b),
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_HELMET), r, g, b))));
contents.set(2, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_CHESTPLATE), r, g, b),
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_CHESTPLATE), r, g, b))));
contents.set(3, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_LEGGINGS), r, g, b),
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_LEGGINGS), r, g, b))));
contents.set(4, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_BOOTS), r, g, b),
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_BOOTS), r, g, b))));
}
private void setRedItem(Player player, InventoryContents contents, int amount) {
contents.set(3, 4, ClickableItem.of(
amount == 0 ? Items.create(Material.RED_STAINED_GLASS, "&cRed", LORE) :
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2Y0NmMzMWQ2ZWU2ZWE2MTlmNzJlNzg1MjMyY2IwNDhhYjI3MDQ2MmRiMGNiMTQ1NDUxNDQzNjI1MWMxYSJ9fX0=",
amount, "&cRed", LORE), inventoryClickEvent -> {
if (inventoryClickEvent.isShiftClick()) {
setRedItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
} else {
setRedItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
}
setLeatherItems(player, contents);
}));
}
private void setRedRandomItem(Player player, InventoryContents contents) {
contents.set(2, 4, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTEzMWRlOGU5NTFmZGQ3YjlhM2QyMzlkN2NjM2FhM2U4NjU1YTMzNmI5OTliOWVkYmI0ZmIzMjljYmQ4NyJ9fX0=",
1, "&cClick to randomize", ""), inventoryClickEvent -> {
setRedItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
setLeatherItems(player, contents);
}));
}
private void setGreenItem(Player player, InventoryContents contents, int amount) {
contents.set(3, 5, ClickableItem.of(
amount == 0 ? Items.create(Material.GREEN_STAINED_GLASS, "&aGreen", LORE) :
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzZmNjlmN2I3NTM4YjQxZGMzNDM5ZjM2NThhYmJkNTlmYWNjYTM2NmYxOTBiY2YxZDZkMGEwMjZjOGY5NiJ9fX0=",
amount, "&aGreen", LORE), inventoryClickEvent -> {
if (inventoryClickEvent.isShiftClick()) {
setGreenItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
} else {
setGreenItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
}
setLeatherItems(player, contents);
}));
}
private void setGreenRandomItem(Player player, InventoryContents contents) {
contents.set(2, 5, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWMzY2VjNjg3NjlmZTljOTcxMjkxZWRiN2VmOTZhNGUzYjYwNDYyY2ZkNWZiNWJhYTFjYmIzYTcxNTEzZTdiIn19fQ==",
1, "&aClick to randomize", ""), inventoryClickEvent -> {
setGreenItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
setLeatherItems(player, contents);
}));
}
private void setBlueItem(Player player, InventoryContents contents, int amount) {
contents.set(3, 6, ClickableItem.of(
amount == 0 ? Items.create(Material.BLUE_STAINED_GLASS, "&bBlue", LORE) :
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjgzOWUzODFkOWZlZGFiNmY4YjU5Mzk2YTI3NjQyMzhkY2ViMmY3ZWVhODU2ZGM2ZmM0NDc2N2RhMzgyZjEifX19",
amount, "&bBlue", LORE), inventoryClickEvent -> {
if (inventoryClickEvent.isShiftClick()) {
setBlueItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
} else {
setBlueItem(player, contents,
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
}
setLeatherItems(player, contents);
}));
}
private void setBlueRandomItem(Player player, InventoryContents contents) {
contents.set(2, 6, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjMyOGYzNzhmMjhhOTg3MjIyNmY1Y2UwNGQ2ZTFkZmExMTE2MTg1ODdmNDhkZmExZmU4MmQwNDMyMTZhNWNmIn19fQ==",
1, "&bClick to randomize", ""), inventoryClickEvent -> {
setBlueItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
setLeatherItems(player, contents);
}));
}
}
@@ -0,0 +1,85 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.menus.bannermenus.BannerMenuProvider;
import net.arcaniax.buildersutilities.menus.inv.InventoryListener;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
public class Menus {
private static final InventoryListener<InventoryCloseEvent> removeGhostItemsListener =
new InventoryListener<>(InventoryCloseEvent.class, inventoryCloseEvent -> {
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
((Player) inventoryCloseEvent.getPlayer()).updateInventory();
}, 1L);
});
public static final SmartInventory BANNER_MENU = SmartInventory.builder()
.manager(Main.getInstance().getInventoryManager())
.id("buildersutilsbanner")
.provider(new BannerMenuProvider())
.size(6, 9)
.listener(removeGhostItemsListener)
.title(ChatColor.BLUE + "Select a base color")
.closeable(true)
.build();
public static final SmartInventory COLOR_MENU = SmartInventory.builder()
.manager(Main.getInstance().getInventoryManager())
.id("buildersutilscolor")
.provider(new ColorMenuProvider())
.size(6, 9)
.listener(removeGhostItemsListener)
.title(ChatColor.BLUE + "Armor Color Creator")
.closeable(true)
.build();
public static final SmartInventory SECRET_BLOCK_MENU = SmartInventory.builder()
.manager(Main.getInstance().getInventoryManager())
.id("buildersutilssecretblock")
.provider(new SecretBlockMenuProvider())
.size(1, 9)
.listener(removeGhostItemsListener)
.title(ChatColor.BLUE + "Secret Blocks")
.closeable(true)
.build();
public static final SmartInventory TOGGLE_MENU = SmartInventory.builder()
.manager(Main.getInstance().getInventoryManager())
.id("buildersutilstoggle")
.provider(new UtilitiesMenuProvider())
.size(3, 9)
.listener(removeGhostItemsListener)
.title(ChatColor.BLUE + "Builder's Utilities")
.closeable(true)
.build();
}
@@ -0,0 +1,54 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus;
import net.arcaniax.buildersutilities.Main;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class SecretBlockMenuProvider implements InventoryProvider {
private static final ItemStack SPAWNER = Items.create(Material.SPAWNER, (short) 0, 1, ChatColor.DARK_AQUA + "Spawner Cage", "");
private static final ItemStack BARRIER = Items.create(Material.BARRIER, (short) 0, 1, ChatColor.DARK_AQUA + "Barrier", "");
private static final ItemStack DRAGON_EGG = Items.create(Material.DRAGON_EGG, (short) 0, 1, ChatColor.DARK_AQUA + "Dragon Egg", "");
private static final ItemStack GRASS_PATH = Items.create(Material.GRASS_PATH, (short) 0, 1, ChatColor.DARK_AQUA + "Grass Path", "");
@Override
public void init(Player player, InventoryContents contents) {
contents.set(0, 0, ClickableItem.of(SPAWNER, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.SPAWNER))));
contents.set(0, 1, ClickableItem.of(BARRIER, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.BARRIER))));
contents.set(0, 2, ClickableItem.of(DRAGON_EGG, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.DRAGON_EGG))));
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 9, 0)) {
contents.set(0, 3, ClickableItem.of(GRASS_PATH, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.GRASS_PATH))));
}
}
}
@@ -0,0 +1,240 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus;
import net.arcaniax.buildersutilities.NoClipManager;
import net.arcaniax.buildersutilities.listeners.BlockBreakListener;
import net.arcaniax.buildersutilities.listeners.IronTrapdoorListener;
import net.arcaniax.buildersutilities.listeners.PlayerMoveListener;
import net.arcaniax.buildersutilities.listeners.TerracottaInteractListener;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class UtilitiesMenuProvider implements InventoryProvider {
private static final ItemStack ENABLED = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
private static final ItemStack DISABLED = new ItemStack(Material.RED_STAINED_GLASS_PANE);
private static final ItemStack NO_PERMISSION = new ItemStack(Material.ORANGE_STAINED_GLASS_PANE);
private static final String ENABLED_LORE = "&a&lEnabled__&7__&7Click to toggle";
private static final String DISABLED_LORE = "&c&lDisabled__&7__&7Click to toggle";
@Override
public void init(Player player, InventoryContents contents) {
setIronTrapdoorItem(player, contents);
setSlabItem(player, contents);
setTerracottaItem(player, contents);
setNightVisionItem(player, contents);
setNoClipItem(player, contents);
setFlyItem(player, contents);
}
private void setIronTrapdoorItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.irontrapdoor")) {
setNoPermission(1, contents);
contents.set(1, 1, ClickableItem.empty(
Items.create(Material.IRON_TRAPDOOR, "&6Iron Trapdoor Interaction", "&7&lNo Permission")));
return;
}
if (IronTrapdoorListener.ironTrapdoorIds.contains(player.getUniqueId())) {
setEnabledGlassPanes(1, true, contents);
contents.set(1, 1, ClickableItem.of(Items.create(Material.IRON_TRAPDOOR,
"&6Iron Trapdoor Interaction", ENABLED_LORE),
inventoryClickEvent -> {
IronTrapdoorListener.ironTrapdoorIds.remove(player.getUniqueId());
setIronTrapdoorItem(player, contents);
}));
} else {
setEnabledGlassPanes(1, false, contents);
contents.set(1, 1, ClickableItem.of(Items.create(Material.IRON_TRAPDOOR,
"&6Iron Trapdoor Interaction", DISABLED_LORE),
inventoryClickEvent -> {
IronTrapdoorListener.ironTrapdoorIds.add(player.getUniqueId());
setIronTrapdoorItem(player, contents);
}));
}
}
private void setSlabItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.slabs")) {
setNoPermission(2, contents);
contents.set(1, 2, ClickableItem.empty(
Items.create(Material.STONE_SLAB, "&6Custom Slab Breaking", "&7&lNo Permission")));
return;
}
if (BlockBreakListener.slabIds.contains(player.getUniqueId())) {
setEnabledGlassPanes(2, true, contents);
contents.set(1, 2, ClickableItem.of(Items.create(Material.STONE_SLAB,
"&6Custom Slab Breaking", ENABLED_LORE),
inventoryClickEvent -> {
BlockBreakListener.slabIds.remove(player.getUniqueId());
setSlabItem(player, contents);
}));
} else {
setEnabledGlassPanes(2, false, contents);
contents.set(1, 2, ClickableItem.of(Items.create(Material.STONE_SLAB,
"&6Custom Slab Breaking", DISABLED_LORE),
inventoryClickEvent -> {
BlockBreakListener.slabIds.add(player.getUniqueId());
setSlabItem(player, contents);
}));
}
}
private void setTerracottaItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.terracotta")) {
setNoPermission(3, contents);
contents.set(1, 3, ClickableItem.empty(
Items.create(Material.ORANGE_GLAZED_TERRACOTTA, "&6Glazed Terracotta Rotating", "&7&lNo Permission")));
return;
}
if (TerracottaInteractListener.terracottaIds.contains(player.getUniqueId())) {
setEnabledGlassPanes(3, true, contents);
contents.set(1, 3, ClickableItem.of(Items.create(Material.ORANGE_GLAZED_TERRACOTTA,
"&6Glazed Terracotta Rotating", ENABLED_LORE),
inventoryClickEvent -> {
TerracottaInteractListener.terracottaIds.remove(player.getUniqueId());
setTerracottaItem(player, contents);
}));
} else {
setEnabledGlassPanes(3, false, contents);
contents.set(1, 3, ClickableItem.of(Items.create(Material.ORANGE_GLAZED_TERRACOTTA,
"&6Glazed Terracotta Rotating", DISABLED_LORE),
inventoryClickEvent -> {
TerracottaInteractListener.terracottaIds.add(player.getUniqueId());
setTerracottaItem(player, contents);
}));
}
}
private void setNightVisionItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.nightvision")) {
setNoPermission(5, contents);
contents.set(1, 5, ClickableItem.empty(
Items.create(Material.ENDER_EYE, "&6Night Vision", "&7&lNo Permission")));
return;
}
if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
setEnabledGlassPanes(5, true, contents);
contents.set(1, 5, ClickableItem.of(Items.create(Material.ENDER_EYE,
"&6Night Vision", ENABLED_LORE),
inventoryClickEvent -> {
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
setNightVisionItem(player, contents);
}));
} else {
setEnabledGlassPanes(5, false, contents);
contents.set(1, 5, ClickableItem.of(Items.create(Material.ENDER_EYE,
"&6Night Vision", DISABLED_LORE),
inventoryClickEvent -> {
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, true, false));
setNightVisionItem(player, contents);
}));
}
}
private void setNoClipItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.noclip")) {
setNoPermission(6, contents);
contents.set(1, 6, ClickableItem.empty(
Items.create(Material.COMPASS, "&6No Clip", "&7&lNo Permission")));
return;
}
if (NoClipManager.noClipPlayerIds.contains(player.getUniqueId())) {
setEnabledGlassPanes(6, true, contents);
contents.set(1, 6, ClickableItem.of(Items.create(Material.COMPASS,
"&6No Clip", ENABLED_LORE),
inventoryClickEvent -> {
NoClipManager.noClipPlayerIds.remove(player.getUniqueId());
setNoClipItem(player, contents);
}));
} else {
setEnabledGlassPanes(6, false, contents);
contents.set(1, 6, ClickableItem.of(Items.create(Material.COMPASS,
"&6No Clip", DISABLED_LORE),
inventoryClickEvent -> {
NoClipManager.noClipPlayerIds.add(player.getUniqueId());
setNoClipItem(player, contents);
}));
}
}
private void setFlyItem(Player player, InventoryContents contents) {
if (!player.hasPermission("builders.util.advancedfly")) {
setNoPermission(7, contents);
contents.set(1, 7, ClickableItem.empty(
Items.create(Material.FEATHER, "&6Advanced Fly", "&7&lNo Permission")));
return;
}
if (PlayerMoveListener.enabledPlayers.contains(player.getUniqueId())) {
setEnabledGlassPanes(7, true, contents);
contents.set(1, 7, ClickableItem.of(Items.create(Material.FEATHER,
"&6Advanced Fly", ENABLED_LORE),
inventoryClickEvent -> {
PlayerMoveListener.enabledPlayers.remove(player.getUniqueId());
setFlyItem(player, contents);
}));
} else {
setEnabledGlassPanes(7, false, contents);
contents.set(1, 7, ClickableItem.of(Items.create(Material.FEATHER,
"&6Advanced Fly", DISABLED_LORE),
inventoryClickEvent -> {
PlayerMoveListener.enabledPlayers.add(player.getUniqueId());
setFlyItem(player, contents);
}));
}
}
/**
* Sets the glass panes above and below the center row to
* show if a feature is enabled or disabled.
* https://i.imgur.com/ETI22Py.png
*
* @param col the column to set the glass panes in
* @param enabled true if green panes, false if red panes
*/
private void setEnabledGlassPanes(int col, boolean enabled, InventoryContents contents) {
contents.set(0, col, ClickableItem.empty(enabled ? ENABLED : DISABLED));
contents.set(2, col, ClickableItem.empty(enabled ? ENABLED : DISABLED));
}
private void setNoPermission(int col, InventoryContents contents) {
contents.set(0, col, ClickableItem.empty(NO_PERMISSION));
contents.set(2, col, ClickableItem.empty(NO_PERMISSION));
}
}
@@ -0,0 +1,61 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.bannermenus;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class BannerColorMenuProvider implements InventoryProvider {
private static final ItemStack grayPane = Items
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
private static final ItemStack head = Items.createHead(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
1, "&7Click to randomise", "");
@Override
public void init(Player player, InventoryContents contents) {
// for (int x = 0; x < 54; x++) {
// contents.set(x / 9, x % 9, grayPane);
// }
// inv1.setItem(1, );
// if (first) {
// inv1.setItem(4, bU.createBanner("&aClick to get the banner", 1, DyeColor.valueOf(clicked.getType().toString().replace("_BANNER", "")), ""));
// } else {
// inv1.setItem(4, bU.addPattern(inv.getItem(4), new Pattern(bU.getColorFromBanner(clicked), bU.getPatternType(clicked))));
// }
// inv1.setItem(7, i.create(Material.BARRIER, (short) 0, 1, "&cClick to close", ""));
// for (int x = 19; x < 27; x++) {
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 19), 1, "&3" + bU.getAllColors().get(x - 19).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
// }
// for (int x = 28; x < 36; x++) {
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 20), 1, "&3" + bU.getAllColors().get(x - 20).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
// }
}
}
@@ -0,0 +1,62 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.bannermenus;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class BannerMenuProvider implements InventoryProvider {
private static final ItemStack grayPane = Items
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
private static final ItemStack randomizeHead = Items.createHead(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
1, "&7Click to randomise", "");
// private static final ItemStack currentColor = BannerUtil.createBanner("&a", 1, DyeColor.WHITE, "");
private static final ItemStack closeButton = Items
.create(Material.BARRIER, (short) 0, 1, "&cClick to close", "");
@Override
public void init(Player player, InventoryContents contents) {
// for (int x = 0; x < 54; x++) {
// contents.set(x / 9, x % 9, ClickableItem.empty(grayPane));
// }
// contents.set(0, 1, ClickableItem.of(randomizeHead, NULL));
// contents.set(0, 4, ClickableItem.empty(currentColor));
// contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
// for (int x = 19; x < 27; x++) {
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 19).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 19), "&7__&7click to select");
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
// }
// for (int x = 28; x < 36; x++) {
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 28 + 8).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 28 + 8), "&7__&7click to select");
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
// }
}
}
@@ -0,0 +1,62 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.bannermenus;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class BannerPatternMenuProvider implements InventoryProvider {
private static final ItemStack grayPane = Items
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
private static final ItemStack randomizeHead = Items.createHead(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
1, "&7Click to randomise", "");
// private static final ItemStack currentColor = BannerUtil.createBanner("&a", 1, DyeColor.WHITE, "");
private static final ItemStack closeButton = Items
.create(Material.BARRIER, (short) 0, 1, "&cClick to close", "");
@Override
public void init(Player player, InventoryContents contents) {
// for (int x = 0; x < 54; x++) {
// contents.set(x / 9, x % 9, ClickableItem.empty(grayPane));
// }
// contents.set(0, 1, ClickableItem.of(randomizeHead, NULL));
// contents.set(0, 4, ClickableItem.empty(currentColor));
// contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
// for (int x = 19; x < 27; x++) {
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 19).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 19), "&7__&7click to select");
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
// }
// for (int x = 28; x < 36; x++) {
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 28 + 8).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 28 + 8), "&7__&7click to select");
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
// }
}
}
@@ -0,0 +1,59 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.util.function.Consumer;
public class ClickableItem {
private final ItemStack item;
private final Consumer<InventoryClickEvent> consumer;
private ClickableItem(ItemStack item, Consumer<InventoryClickEvent> consumer) {
this.item = item;
this.consumer = consumer;
}
public static ClickableItem empty(ItemStack item) {
return of(item, e -> {
});
}
public static ClickableItem of(ItemStack item, Consumer<InventoryClickEvent> consumer) {
return new ClickableItem(item, consumer);
}
public void run(InventoryClickEvent e) {
consumer.accept(e);
}
public ItemStack getItem() {
return item;
}
}
@@ -0,0 +1,47 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv;
import java.util.function.Consumer;
public class InventoryListener<T> {
private final Class<T> type;
private final Consumer<T> consumer;
public InventoryListener(Class<T> type, Consumer<T> consumer) {
this.type = type;
this.consumer = consumer;
}
public void accept(T t) {
consumer.accept(t);
}
public Class<T> getType() {
return type;
}
}
@@ -0,0 +1,288 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.opener.ChestInventoryOpener;
import net.arcaniax.buildersutilities.menus.inv.opener.InventoryOpener;
import net.arcaniax.buildersutilities.menus.inv.opener.SpecialInventoryOpener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
public class InventoryManager {
private final JavaPlugin plugin;
private final PluginManager pluginManager;
private final Map<Player, SmartInventory> inventories;
private final Map<Player, InventoryContents> contents;
private final List<InventoryOpener> defaultOpeners;
private final List<InventoryOpener> openers;
public InventoryManager(JavaPlugin plugin) {
this.plugin = plugin;
this.pluginManager = Bukkit.getPluginManager();
this.inventories = new HashMap<>();
this.contents = new HashMap<>();
this.defaultOpeners = Arrays.asList(
new ChestInventoryOpener(),
new SpecialInventoryOpener()
);
this.openers = new ArrayList<>();
}
public void init() {
pluginManager.registerEvents(new InvListener(), plugin);
new InvTask().runTaskTimer(plugin, 1, 1);
}
public Optional<InventoryOpener> findOpener(InventoryType type) {
Optional<InventoryOpener> opInv = this.openers.stream()
.filter(opener -> opener.supports(type))
.findAny();
if (!opInv.isPresent()) {
opInv = this.defaultOpeners.stream()
.filter(opener -> opener.supports(type))
.findAny();
}
return opInv;
}
public void registerOpeners(InventoryOpener... openers) {
this.openers.addAll(Arrays.asList(openers));
}
public List<Player> getOpenedPlayers(SmartInventory inv) {
List<Player> list = new ArrayList<>();
this.inventories.forEach((player, playerInv) -> {
if (inv.equals(playerInv)) {
list.add(player);
}
});
return list;
}
public Optional<SmartInventory> getInventory(Player p) {
return Optional.ofNullable(this.inventories.get(p));
}
protected void setInventory(Player p, SmartInventory inv) {
if (inv == null) {
this.inventories.remove(p);
} else {
this.inventories.put(p, inv);
}
}
public Optional<InventoryContents> getContents(Player p) {
return Optional.ofNullable(this.contents.get(p));
}
protected void setContents(Player p, InventoryContents contents) {
if (contents == null) {
this.contents.remove(p);
} else {
this.contents.put(p, contents);
}
}
@SuppressWarnings("unchecked")
class InvListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
if (!inventories.containsKey(p)) {
return;
}
if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
e.setCancelled(true);
}
if (e.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
e.setCancelled(true);
return;
}
if (e.getAction() == InventoryAction.NOTHING && e.getClick() != ClickType.MIDDLE) {
e.setCancelled(true);
}
if (e.getClickedInventory() == p.getOpenInventory().getTopInventory()) {
e.setCancelled(true);
int row = e.getSlot() / 9;
int column = e.getSlot() % 9;
if (row < 0 || column < 0) {
return;
}
SmartInventory inv = inventories.get(p);
if (row >= inv.getRows() || column >= inv.getColumns()) {
return;
}
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryClickEvent.class)
.forEach(listener -> ((InventoryListener<InventoryClickEvent>) listener).accept(e));
contents.get(p).get(row, column).ifPresent(item -> item.run(e));
p.updateInventory();
}
}
@EventHandler(priority = EventPriority.LOW)
public void onInventoryDrag(InventoryDragEvent e) {
Player p = (Player) e.getWhoClicked();
if (!inventories.containsKey(p)) {
return;
}
SmartInventory inv = inventories.get(p);
for (int slot : e.getRawSlots()) {
if (slot >= p.getOpenInventory().getTopInventory().getSize()) {
continue;
}
e.setCancelled(true);
break;
}
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryDragEvent.class)
.forEach(listener -> ((InventoryListener<InventoryDragEvent>) listener).accept(e));
}
@EventHandler(priority = EventPriority.LOW)
public void onInventoryOpen(InventoryOpenEvent e) {
Player p = (Player) e.getPlayer();
if (!inventories.containsKey(p)) {
return;
}
SmartInventory inv = inventories.get(p);
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryOpenEvent.class)
.forEach(listener -> ((InventoryListener<InventoryOpenEvent>) listener).accept(e));
}
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClose(InventoryCloseEvent e) {
Player p = (Player) e.getPlayer();
if (!inventories.containsKey(p)) {
return;
}
SmartInventory inv = inventories.get(p);
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener).accept(e));
if (inv.isCloseable()) {
e.getInventory().clear();
inventories.remove(p);
contents.remove(p);
} else {
Bukkit.getScheduler().runTask(plugin, () -> p.openInventory(e.getInventory()));
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerQuit(PlayerQuitEvent e) {
Player p = e.getPlayer();
if (!inventories.containsKey(p)) {
return;
}
SmartInventory inv = inventories.get(p);
inv.getListeners().stream()
.filter(listener -> listener.getType() == PlayerQuitEvent.class)
.forEach(listener -> ((InventoryListener<PlayerQuitEvent>) listener).accept(e));
inventories.remove(p);
contents.remove(p);
}
@EventHandler(priority = EventPriority.LOW)
public void onPluginDisable(PluginDisableEvent e) {
new HashMap<>(inventories).forEach((player, inv) -> {
inv.getListeners().stream()
.filter(listener -> listener.getType() == PluginDisableEvent.class)
.forEach(listener -> ((InventoryListener<PluginDisableEvent>) listener).accept(e));
inv.close(player);
});
inventories.clear();
contents.clear();
}
}
class InvTask extends BukkitRunnable {
@Override
public void run() {
new HashMap<>(inventories)
.forEach((player, inv) -> inv.getProvider().update(player, contents.get(player)));
}
}
}
@@ -0,0 +1,240 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.menus.inv.opener.InventoryOpener;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@SuppressWarnings("unchecked")
public class SmartInventory {
private final InventoryManager manager;
private String id;
private String title;
private InventoryType type;
private int rows, columns;
private boolean closeable;
private InventoryProvider provider;
private SmartInventory parent;
private List<InventoryListener<? extends Event>> listeners;
private SmartInventory(InventoryManager manager) {
this.manager = manager;
}
public static Builder builder() {
return new Builder();
}
public Inventory open(Player player) {
return open(player, 0);
}
public Inventory open(Player player, int page) {
Optional<SmartInventory> oldInv = this.manager.getInventory(player);
oldInv.ifPresent(inv -> {
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener)
.accept(new InventoryCloseEvent(player.getOpenInventory())));
this.manager.setInventory(player, null);
});
InventoryContents contents = new InventoryContents.Impl(this, player);
contents.pagination().page(page);
this.manager.setContents(player, contents);
this.provider.init(player, contents);
InventoryOpener opener = this.manager.findOpener(type)
.orElseThrow(() -> new IllegalStateException(
"No opener found for the inventory type " + type.name()));
Inventory handle = opener.open(this, player);
this.manager.setInventory(player, this);
return handle;
}
@SuppressWarnings("unchecked")
public void close(Player player) {
listeners.stream()
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener)
.accept(new InventoryCloseEvent(player.getOpenInventory())));
this.manager.setInventory(player, null);
player.closeInventory();
this.manager.setContents(player, null);
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public InventoryType getType() {
return type;
}
public int getRows() {
return rows;
}
public int getColumns() {
return columns;
}
public boolean isCloseable() {
return closeable;
}
public void setCloseable(boolean closeable) {
this.closeable = closeable;
}
public InventoryProvider getProvider() {
return provider;
}
public Optional<SmartInventory> getParent() {
return Optional.ofNullable(parent);
}
public InventoryManager getManager() {
return manager;
}
List<InventoryListener<? extends Event>> getListeners() {
return listeners;
}
public static final class Builder {
private final List<InventoryListener<? extends Event>> listeners = new ArrayList<>();
private String id = "unknown";
private String title = "";
private InventoryType type = InventoryType.CHEST;
private int rows = 6, columns = 9;
private boolean closeable = true;
private InventoryManager manager;
private InventoryProvider provider;
private SmartInventory parent;
private Builder() {
}
public Builder id(String id) {
this.id = id;
return this;
}
public Builder title(String title) {
this.title = title;
return this;
}
public Builder type(InventoryType type) {
this.type = type;
return this;
}
public Builder size(int rows, int columns) {
this.rows = rows;
this.columns = columns;
return this;
}
public Builder closeable(boolean closeable) {
this.closeable = closeable;
return this;
}
public Builder provider(InventoryProvider provider) {
this.provider = provider;
return this;
}
public Builder parent(SmartInventory parent) {
this.parent = parent;
return this;
}
public Builder listener(InventoryListener<? extends Event> listener) {
this.listeners.add(listener);
return this;
}
public Builder manager(InventoryManager manager) {
this.manager = manager;
return this;
}
public SmartInventory build() {
if (this.provider == null) {
throw new IllegalStateException(
"The provider of the SmartInventory.Builder must be set.");
}
InventoryManager manager = this.manager;
if (manager == null) {
throw new IllegalStateException(
"The manager of the SmartInventory.Builder must be set, "
+ "or the SmartInvs should be loaded as a plugin.");
}
SmartInventory inv = new SmartInventory(manager);
inv.id = this.id;
inv.title = this.title;
inv.type = this.type;
inv.rows = this.rows;
inv.columns = this.columns;
inv.closeable = this.closeable;
inv.provider = this.provider;
inv.parent = this.parent;
inv.listeners = this.listeners;
return inv;
}
}
}
@@ -0,0 +1,301 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.content;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public interface InventoryContents {
SmartInventory inventory();
Pagination pagination();
Optional<SlotIterator> iterator(String id);
SlotIterator newIterator(String id, SlotIterator.Type type, int startRow, int startColumn);
SlotIterator newIterator(SlotIterator.Type type, int startRow, int startColumn);
SlotIterator newIterator(String id, SlotIterator.Type type, SlotPos startPos);
SlotIterator newIterator(SlotIterator.Type type, SlotPos startPos);
ClickableItem[][] all();
Optional<SlotPos> firstEmpty();
Optional<ClickableItem> get(int row, int column);
Optional<ClickableItem> get(SlotPos slotPos);
InventoryContents set(int row, int column, ClickableItem item);
InventoryContents set(SlotPos slotPos, ClickableItem item);
InventoryContents add(ClickableItem item);
InventoryContents fill(ClickableItem item);
InventoryContents fillRow(int row, ClickableItem item);
InventoryContents fillColumn(int column, ClickableItem item);
InventoryContents fillBorders(ClickableItem item);
InventoryContents fillRect(int fromRow, int fromColumn,
int toRow, int toColumn, ClickableItem item);
InventoryContents fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item);
<T> T property(String name);
<T> T property(String name, T def);
InventoryContents setProperty(String name, Object value);
class Impl implements InventoryContents {
private final SmartInventory inv;
private final Player player;
private final ClickableItem[][] contents;
private final Pagination pagination = new Pagination.Impl();
private final Map<String, SlotIterator> iterators = new HashMap<>();
private final Map<String, Object> properties = new HashMap<>();
public Impl(SmartInventory inv, Player player) {
this.inv = inv;
this.player = player;
this.contents = new ClickableItem[inv.getRows()][inv.getColumns()];
}
@Override
public SmartInventory inventory() {
return inv;
}
@Override
public Pagination pagination() {
return pagination;
}
@Override
public Optional<SlotIterator> iterator(String id) {
return Optional.ofNullable(this.iterators.get(id));
}
@Override
public SlotIterator newIterator(String id, SlotIterator.Type type, int startRow,
int startColumn) {
SlotIterator iterator = new SlotIterator.Impl(this, inv,
type, startRow, startColumn);
this.iterators.put(id, iterator);
return iterator;
}
@Override
public SlotIterator newIterator(String id, SlotIterator.Type type, SlotPos startPos) {
return newIterator(id, type, startPos.getRow(), startPos.getColumn());
}
@Override
public SlotIterator newIterator(SlotIterator.Type type, int startRow, int startColumn) {
return new SlotIterator.Impl(this, inv, type, startRow, startColumn);
}
@Override
public SlotIterator newIterator(SlotIterator.Type type, SlotPos startPos) {
return newIterator(type, startPos.getRow(), startPos.getColumn());
}
@Override
public ClickableItem[][] all() {
return contents;
}
@Override
public Optional<SlotPos> firstEmpty() {
for (int row = 0; row < contents.length; row++) {
for (int column = 0; column < contents[0].length; column++) {
if (!this.get(row, column).isPresent()) {
return Optional.of(new SlotPos(row, column));
}
}
}
return Optional.empty();
}
@Override
public Optional<ClickableItem> get(int row, int column) {
if (row >= contents.length) {
return Optional.empty();
}
if (column >= contents[row].length) {
return Optional.empty();
}
return Optional.ofNullable(contents[row][column]);
}
@Override
public Optional<ClickableItem> get(SlotPos slotPos) {
return get(slotPos.getRow(), slotPos.getColumn());
}
@Override
public InventoryContents set(int row, int column, ClickableItem item) {
if (row >= contents.length) {
return this;
}
if (column >= contents[row].length) {
return this;
}
contents[row][column] = item;
update(row, column, item != null ? item.getItem() : null);
return this;
}
@Override
public InventoryContents set(SlotPos slotPos, ClickableItem item) {
return set(slotPos.getRow(), slotPos.getColumn(), item);
}
@Override
public InventoryContents add(ClickableItem item) {
for (int row = 0; row < contents.length; row++) {
for (int column = 0; column < contents[0].length; column++) {
if (contents[row][column] == null) {
set(row, column, item);
return this;
}
}
}
return this;
}
@Override
public InventoryContents fill(ClickableItem item) {
for (int row = 0; row < contents.length; row++) {
for (int column = 0; column < contents[row].length; column++) {
set(row, column, item);
}
}
return this;
}
@Override
public InventoryContents fillRow(int row, ClickableItem item) {
if (row >= contents.length) {
return this;
}
for (int column = 0; column < contents[row].length; column++) {
set(row, column, item);
}
return this;
}
@Override
public InventoryContents fillColumn(int column, ClickableItem item) {
for (int row = 0; row < contents.length; row++) {
set(row, column, item);
}
return this;
}
@Override
public InventoryContents fillBorders(ClickableItem item) {
fillRect(0, 0, inv.getRows() - 1, inv.getColumns() - 1, item);
return this;
}
@Override
public InventoryContents fillRect(int fromRow, int fromColumn, int toRow, int toColumn,
ClickableItem item) {
for (int row = fromRow; row <= toRow; row++) {
for (int column = fromColumn; column <= toColumn; column++) {
if (row != fromRow && row != toRow && column != fromColumn && column != toColumn) {
continue;
}
set(row, column, item);
}
}
return this;
}
@Override
public InventoryContents fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item) {
return fillRect(fromPos.getRow(), fromPos.getColumn(), toPos.getRow(), toPos.getColumn(),
item);
}
@SuppressWarnings("unchecked")
@Override
public <T> T property(String name) {
return (T) properties.get(name);
}
@SuppressWarnings("unchecked")
@Override
public <T> T property(String name, T def) {
return properties.containsKey(name) ? (T) properties.get(name) : def;
}
@Override
public InventoryContents setProperty(String name, Object value) {
properties.put(name, value);
return this;
}
private void update(int row, int column, ItemStack item) {
if (!inv.getManager().getOpenedPlayers(inv).contains(player)) {
return;
}
Inventory topInventory = player.getOpenInventory().getTopInventory();
topInventory.setItem(inv.getColumns() * row + column, item);
}
}
}
@@ -0,0 +1,36 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.content;
import org.bukkit.entity.Player;
public interface InventoryProvider {
void init(Player player, InventoryContents contents);
default void update(Player player, InventoryContents contents) {
}
}
@@ -0,0 +1,151 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.content;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import java.util.Arrays;
public interface Pagination {
ClickableItem[] getPageItems();
int getPage();
Pagination page(int page);
boolean isFirst();
boolean isLast();
Pagination first();
Pagination previous();
Pagination next();
Pagination last();
Pagination addToIterator(SlotIterator iterator);
Pagination setItems(ClickableItem... items);
Pagination setItemsPerPage(int itemsPerPage);
class Impl implements Pagination {
private int currentPage;
private ClickableItem[] items = new ClickableItem[0];
private int itemsPerPage = 5;
@Override
public ClickableItem[] getPageItems() {
return Arrays.copyOfRange(items,
currentPage * itemsPerPage,
(currentPage + 1) * itemsPerPage);
}
@Override
public int getPage() {
return this.currentPage;
}
@Override
public Pagination page(int page) {
this.currentPage = page;
return this;
}
@Override
public boolean isFirst() {
return this.currentPage == 0;
}
@Override
public boolean isLast() {
int pageCount = (int) Math.ceil((double) this.items.length / this.itemsPerPage);
return this.currentPage >= pageCount - 1;
}
@Override
public Pagination first() {
this.currentPage = 0;
return this;
}
@Override
public Pagination previous() {
if (!isFirst()) {
this.currentPage--;
}
return this;
}
@Override
public Pagination next() {
if (!isLast()) {
this.currentPage++;
}
return this;
}
@Override
public Pagination last() {
this.currentPage = this.items.length / this.itemsPerPage;
return this;
}
@Override
public Pagination addToIterator(SlotIterator iterator) {
for (ClickableItem item : getPageItems()) {
iterator.next().set(item);
if (iterator.ended()) {
break;
}
}
return this;
}
@Override
public Pagination setItems(ClickableItem... items) {
this.items = items;
return this;
}
@Override
public Pagination setItemsPerPage(int itemsPerPage) {
this.itemsPerPage = itemsPerPage;
return this;
}
}
}
@@ -0,0 +1,244 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.content;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public interface SlotIterator {
Optional<ClickableItem> get();
SlotIterator set(ClickableItem item);
SlotIterator previous();
SlotIterator next();
SlotIterator blacklist(int row, int column);
SlotIterator blacklist(SlotPos slotPos);
int row();
SlotIterator row(int row);
int column();
SlotIterator column(int column);
boolean started();
boolean ended();
boolean doesAllowOverride();
SlotIterator allowOverride(boolean override);
enum Type {
HORIZONTAL,
VERTICAL
}
class Impl implements SlotIterator {
private final InventoryContents contents;
private final SmartInventory inv;
private final Type type;
private final Set<SlotPos> blacklisted = new HashSet<>();
private boolean started = false;
private boolean allowOverride = true;
private int row, column;
public Impl(InventoryContents contents, SmartInventory inv,
Type type, int startRow, int startColumn) {
this.contents = contents;
this.inv = inv;
this.type = type;
this.row = startRow;
this.column = startColumn;
}
public Impl(InventoryContents contents, SmartInventory inv,
Type type) {
this(contents, inv, type, 0, 0);
}
@Override
public Optional<ClickableItem> get() {
return contents.get(row, column);
}
@Override
public SlotIterator set(ClickableItem item) {
if (canPlace()) {
contents.set(row, column, item);
}
return this;
}
@Override
public SlotIterator previous() {
if (row == 0 && column == 0) {
this.started = true;
return this;
}
do {
if (!this.started) {
this.started = true;
} else {
switch (type) {
case HORIZONTAL:
column--;
if (column == 0) {
column = inv.getColumns() - 1;
row--;
}
break;
case VERTICAL:
row--;
if (row == 0) {
row = inv.getRows() - 1;
column--;
}
break;
}
}
}
while (!canPlace() && (row != 0 || column != 0));
return this;
}
@Override
public SlotIterator next() {
if (ended()) {
this.started = true;
return this;
}
do {
if (!this.started) {
this.started = true;
} else {
switch (type) {
case HORIZONTAL:
column = ++column % inv.getColumns();
if (column == 0) {
row++;
}
break;
case VERTICAL:
row = ++row % inv.getRows();
if (row == 0) {
column++;
}
break;
}
}
}
while (!canPlace() && !ended());
return this;
}
@Override
public SlotIterator blacklist(int row, int column) {
this.blacklisted.add(SlotPos.of(row, column));
return this;
}
@Override
public SlotIterator blacklist(SlotPos slotPos) {
return blacklist(slotPos.getRow(), slotPos.getColumn());
}
@Override
public int row() {
return row;
}
@Override
public SlotIterator row(int row) {
this.row = row;
return this;
}
@Override
public int column() {
return column;
}
@Override
public SlotIterator column(int column) {
this.column = column;
return this;
}
@Override
public boolean started() {
return this.started;
}
@Override
public boolean ended() {
return row == inv.getRows() - 1
&& column == inv.getColumns() - 1;
}
@Override
public boolean doesAllowOverride() {
return allowOverride;
}
@Override
public SlotIterator allowOverride(boolean override) {
this.allowOverride = override;
return this;
}
private boolean canPlace() {
return !blacklisted.contains(SlotPos.of(row, column)) && (allowOverride || !this.get()
.isPresent());
}
}
}
@@ -0,0 +1,71 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.content;
public class SlotPos {
private final int row;
private final int column;
public SlotPos(int row, int column) {
this.row = row;
this.column = column;
}
public static SlotPos of(int row, int column) {
return new SlotPos(row, column);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
SlotPos slotPos = (SlotPos) obj;
return row == slotPos.row && column == slotPos.column;
}
@Override
public int hashCode() {
int result = row;
result = 31 * result + column;
return result;
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
}
@@ -0,0 +1,59 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.opener;
import com.google.common.base.Preconditions;
import net.arcaniax.buildersutilities.menus.inv.InventoryManager;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
public class ChestInventoryOpener implements InventoryOpener {
@Override
public Inventory open(SmartInventory inv, Player player) {
Preconditions.checkArgument(inv.getColumns() == 9,
"The column count for the chest inventory must be 9, found: %s.", inv.getColumns());
Preconditions.checkArgument(inv.getRows() >= 1 && inv.getRows() <= 6,
"The row count for the chest inventory must be between 1 and 6, found: %s", inv.getRows());
InventoryManager manager = inv.getManager();
Inventory handle = Bukkit
.createInventory(player, inv.getRows() * inv.getColumns(), inv.getTitle());
fill(handle, manager.getContents(player).get());
player.openInventory(handle);
return handle;
}
@Override
public boolean supports(InventoryType type) {
return type == InventoryType.CHEST || type == InventoryType.ENDER_CHEST;
}
}
@@ -0,0 +1,52 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.opener;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
public interface InventoryOpener {
Inventory open(SmartInventory inv, Player player);
boolean supports(InventoryType type);
default void fill(Inventory handle, InventoryContents contents) {
ClickableItem[][] items = contents.all();
for (int row = 0; row < items.length; row++) {
for (int column = 0; column < items[row].length; column++) {
if (items[row][column] != null) {
handle.setItem(9 * row + column, items[row][column].getItem());
}
}
}
}
}
@@ -0,0 +1,67 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.menus.inv.opener;
import com.google.common.collect.ImmutableList;
import net.arcaniax.buildersutilities.menus.inv.InventoryManager;
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import java.util.List;
public class SpecialInventoryOpener implements InventoryOpener {
private static final List<InventoryType> SUPPORTED = ImmutableList.of(
InventoryType.FURNACE,
InventoryType.WORKBENCH,
InventoryType.DISPENSER,
InventoryType.DROPPER,
InventoryType.ENCHANTING,
InventoryType.BREWING,
InventoryType.ANVIL,
InventoryType.BEACON,
InventoryType.HOPPER
);
@Override
public Inventory open(SmartInventory inv, Player player) {
InventoryManager manager = inv.getManager();
Inventory handle = Bukkit.createInventory(player, inv.getType(), inv.getTitle());
fill(handle, manager.getContents(player).get());
player.openInventory(handle);
return handle;
}
@Override
public boolean supports(InventoryType type) {
return SUPPORTED.contains(type);
}
}
@@ -0,0 +1,221 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
//
//import net.arcaniax.buildersutilities.Main;
//import org.bukkit.ChatColor;
//import org.bukkit.DyeColor;
//import org.bukkit.block.banner.Pattern;
//import org.bukkit.block.banner.PatternType;
//import org.bukkit.inventory.ItemStack;
//import org.bukkit.inventory.meta.BannerMeta;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Random;
//
//public class BannerUtil {
// public static final List<DyeColor> allColors = new ArrayList<>();
// public static final List<PatternType> allPatterns = new ArrayList<>();
// private static final Random random = new Random();
//
// {
// addColors();
// addPatterns();
// }
//
// private void addPatterns() {
// for (PatternType pt : PatternType.values()) {
// if (!pt.equals(PatternType.BASE)) {
// allPatterns.add(pt);
// }
// }
// }
//
// private void addColors() {
// allColors.add(DyeColor.BLACK);
// allColors.add(DyeColor.RED);
// allColors.add(DyeColor.GREEN);
// allColors.add(DyeColor.BROWN);
// allColors.add(DyeColor.BLUE);
// allColors.add(DyeColor.PURPLE);
// allColors.add(DyeColor.CYAN);
// allColors.add(DyeColor.LIGHT_GRAY);
// allColors.add(DyeColor.GRAY);
// allColors.add(DyeColor.PINK);
// allColors.add(DyeColor.LIME);
// allColors.add(DyeColor.YELLOW);
// allColors.add(DyeColor.LIGHT_BLUE);
// allColors.add(DyeColor.MAGENTA);
// allColors.add(DyeColor.ORANGE);
// allColors.add(DyeColor.WHITE);
// }
//
// public static ItemStack createBanner(String name, DyeColor base, String lore, List<Pattern> patterns) {
// ItemStack item = Items.create(XMaterial.fromString(base.toString() + "_BANNER").parseMaterial(), (short) 0, 1, name, "");
// BannerMeta meta = (BannerMeta) item.getItemMeta();
// if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 11, 0)) {
// item.setDurability((short) allColors.indexOf(base));
// } else {
// meta.setBaseColor(base);
// }
//
// meta.setPatterns(patterns);
// if (!lore.equals("")) {
// String[] loreListArray = lore.split("__");
// List<String> loreList = new ArrayList<>();
// for (String s : loreListArray) {
// loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
// }
// meta.setLore(loreList);
// }
// item.setItemMeta(meta);
// return item;
// }
//
// public static ItemStack createBanner(String name, int amount, DyeColor base, String lore) {
// //TODO this might be how we fix it:
// XMaterial.matchXMaterial(base.toString() + "_BANNER").get().parseMaterial();
//
// ItemStack item = Items.create(XMaterial.fromString(base.toString() + "_BANNER").parseMaterial(), (short) 0, 1, name, "");
// BannerMeta meta = (BannerMeta) item.getItemMeta();
// if (!lore.equals("")) {
// String[] loreListArray = lore.split("__");
// List<String> loreList = new ArrayList<>();
// for (String s : loreListArray) {
// loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
// }
// meta.setLore(loreList);
// }
// item.setItemMeta(meta);
// return item;
// }
//
// public static ItemStack createBanner(String name, int amount, DyeColor base, String lore, Pattern pat) {
// ItemStack item = Items.create(XMaterial.fromString(base.toString() + "_BANNER").parseMaterial(), (short) 0, 1, name, "");
// BannerMeta meta = (BannerMeta) item.getItemMeta();
// meta.addPattern(pat);
// if (!lore.equals("")) {
// String[] loreListArray = lore.split("__");
// List<String> loreList = new ArrayList<>();
// for (String s : loreListArray) {
// loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
// }
// meta.setLore(loreList);
// }
// item.setItemMeta(meta);
// return item;
// }
//
// public static ItemStack addPattern(ItemStack i, Pattern pat) {
// if (i.getType().toString().contains("BANNER")) {
// BannerMeta meta = (BannerMeta) i.getItemMeta();
// List<Pattern> patterns = meta.getPatterns();
// patterns.add(pat);
// meta.setPatterns(patterns);
// i.setItemMeta(meta);
// return i;
// }
// return null;
// }
//
// public static DyeColor getBaseColor(ItemStack i) {
// if (i.getType().toString().contains("BANNER")) {
// BannerMeta meta = (BannerMeta) i.getItemMeta();
// if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 11, 0)) {
// return allColors.get(i.getDurability());
// } else {
// return meta.getBaseColor();
// }
//
// }
// return null;
// }
//
// public static PatternType getPatternType(ItemStack i) {
// if (i.getType().toString().contains("BANNER")) {
// BannerMeta meta = (BannerMeta) i.getItemMeta();
// return meta.getPattern(0).getPattern();
// }
// return null;
// }
//
// public static DyeColor getColorFromBanner(ItemStack i) {
// if (i.getType().toString().contains("BANNER")) {
// BannerMeta meta = (BannerMeta) i.getItemMeta();
// return meta.getPattern(0).getColor();
// }
// return null;
// }
//
// public static DyeColor getRandomDye() {
// return allColors.get(random.nextInt(allColors.size()));
// }
//
// public static PatternType getRandomPattern() {
// return allPatterns.get(random.nextInt(allPatterns.size()));
// }
//
// DyeColor getDyeColor(ItemStack i) {
// switch (i.getType()) {
// case INK_SAC:
// return DyeColor.BLACK;
// case ROSE_RED:
// return DyeColor.RED;
// case CACTUS_GREEN:
// return DyeColor.GREEN;
// case COCOA_BEANS:
// return DyeColor.BROWN;
// case LAPIS_LAZULI:
// return DyeColor.BLUE;
// case PURPLE_DYE:
// return DyeColor.PURPLE;
// case CYAN_DYE:
// return DyeColor.CYAN;
// case LIGHT_GRAY_DYE:
// return DyeColor.LIGHT_GRAY;
// case GRAY_DYE:
// return DyeColor.GRAY;
// case PINK_DYE:
// return DyeColor.PINK;
// case LIME_DYE:
// return DyeColor.LIME;
// case DANDELION_YELLOW:
// return DyeColor.YELLOW;
// case LIGHT_BLUE_DYE:
// return DyeColor.LIGHT_BLUE;
// case MAGENTA_DYE:
// return DyeColor.MAGENTA;
// case ORANGE_DYE:
// return DyeColor.ORANGE;
// case BONE_MEAL:
// return DyeColor.WHITE;
// default:
// return DyeColor.BLACK;
// }
// }
//
//
//}
@@ -0,0 +1,137 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import javax.naming.ConfigurationException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class CustomConfig {
private final JavaPlugin plugin;
private final String fileName;
private final File configFile;
private FileConfiguration config;
public CustomConfig(JavaPlugin plugin, File folder, String fileName) {
this.plugin = plugin;
if (!fileName.endsWith(".yml")) {
fileName += ".yml";
}
this.fileName = fileName;
configFile = new File(folder, fileName);
reloadConfig();
}
public CustomConfig(JavaPlugin plugin, String fileName) {
this(plugin, plugin.getDataFolder(), fileName);
}
public void reloadConfig() {
if (!configFile.exists()) {
plugin.getLogger().info("Attempting to save resource: " + configFile.getName());
plugin.saveResource(fileName, true);
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public void saveConfig() {
try {
config.save(configFile);
} catch (Exception e) {
plugin.getLogger().severe(String.format("Couldn't save '%s', because: '%s'", fileName,
e.getMessage()));
}
reloadConfig();
}
public void set(String path, Object value, boolean save) {
config.set(path, value);
if (save) {
saveConfig();
}
}
public void set(String path, Object value) {
set(path, value, false);
}
public Set<String> getKeys(boolean deep) {
return this.config.getKeys(deep);
}
public ConfigurationSection getConfigurationSection(String path) {
return this.config.getConfigurationSection(path);
}
public boolean has(String path) {
return config.contains(path);
}
public <T> T get(String path, Class<T> tClass) {
return get(path, tClass, null);
}
public <T> T get(String path, Class<T> tClass, T tDefault) {
if (tClass.isPrimitive()) {
throw new IllegalArgumentException(
tClass + " is of a primitive type, please use the objectified version.");
}
if (!has(path)) {
if (tDefault == null) {
try {
throw new ConfigurationException(
"Configuration key doesn't exist and the default is null");
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
return tDefault;
}
Object object = config.get(path);
if (object == null) {
return tDefault;
}
if (!tClass.isInstance(object)) {
throw new IllegalArgumentException(path + " is not of type " + tClass.getSimpleName());
}
return tClass.cast(object);
}
public List<String> getStringList(String path) {
if (!has(path)) {
return new ArrayList<>();
}
return config.getStringList(path);
}
}
@@ -0,0 +1,106 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Items {
public static ItemStack create(Material mat, String name, String lore) {
return Items.create(mat, (short) 0, 1, name, lore);
}
public static ItemStack create(Material mat, short data, int amount, String name, String lore) {
ItemStack is = new ItemStack(mat);
is.setAmount(amount);
ItemMeta meta = is.getItemMeta();
if (!lore.equals("")) {
String[] loreListArray = lore.split("__");
List<String> loreList = new ArrayList<>();
for (String s : loreListArray) {
loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
}
meta.setLore(loreList);
}
if (!name.equals("")) {
meta.setDisplayName(name.replace('&', ChatColor.COLOR_CHAR));
}
is.setItemMeta(meta);
is.setDurability(data);
return is;
}
public static ItemStack color(ItemStack is, int r, int g, int b) {
LeatherArmorMeta lam = (LeatherArmorMeta) is.getItemMeta();
Color c = Color.fromRGB(r, g, b);
lam.setColor(c);
is.setItemMeta(lam);
return is;
}
public static ItemStack createHead(String data, int amount, String name, String lore) {
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
if (!lore.equals("")) {
String[] loreListArray = lore.split("__");
List<String> loreList = new ArrayList<>();
for (String s : loreListArray) {
loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
}
meta.setLore(loreList);
}
if (!name.equals("")) {
meta.setDisplayName(name.replace('&', ChatColor.COLOR_CHAR));
}
item.setItemMeta(meta);
SkullMeta headMeta = (SkullMeta) item.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", data));
Field profileField;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);
} catch (Exception ignored) {
}
item.setItemMeta(headMeta);
return item;
}
}
@@ -0,0 +1,744 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) { }
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JsonObject data = new JsonObject();
data.addProperty("serverUUID", serverUUID);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JsonObject data = getServerData();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
// minecraft version 1.14+
if (logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
}
} catch (NoSuchFieldException ignored) { }
}
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public static abstract class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JsonObject getRequestJsonObject() {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JsonObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
}
@@ -0,0 +1,66 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
import net.arcaniax.buildersutilities.Main;
public class NmsManager {
private final String version;
public NmsManager() {
String packageString = Main.getInstance().getServer().getClass().getPackage().getName();
version = packageString.substring(packageString.lastIndexOf('.') + 1);
}
public boolean isVersion(String v) {
return version.equalsIgnoreCase(v);
}
public boolean isVersion(int gameV, int releaseV, int subReleaseV) {
return version.equalsIgnoreCase("v" + gameV + "_" + releaseV + "_R" + subReleaseV);
}
public boolean isAtLeastVersion(int gameV, int releaseV, int subReleaseV) {
String[] split = version.split("_");
int game = Integer.parseInt(split[0].toLowerCase().replace("v", ""));
int release = Integer.parseInt(split[1]);
int subRelease = Integer.parseInt(split[2].toLowerCase().replace("r", ""));
if (game > gameV) {
return true;
} else if (game < gameV) {
return false;
} else {
if (release > releaseV) {
return true;
} else if (release < releaseV) {
return false;
} else {
return subRelease >= subReleaseV;
}
}
}
}
@@ -0,0 +1,51 @@
/*
* ____ _ _ _ _ _ _ _ _ _ _ _
* | _ \ (_) | | | | | | | | (_) (_) | (_)
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
*
* Builder's Utilities is a collection of a lot of tiny features that help with building.
* Copyright (C) 2020 Arcaniax
*
* 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 net.arcaniax.buildersutilities.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Utility {
public static String readFileAsString(File file) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}
}
}
File diff suppressed because it is too large. Load diff