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
+674
View File
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
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/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/philosophy/why-not-lgpl.html>.
+38
View File
@@ -0,0 +1,38 @@
# This disables weather changing from what it currently is
# If it is currently raining, it will continue raining
# If it is currently sunny, it will continue being sunny
# True if you want this feature, false if you do not.
disable-weather-changes: true
# This completely disables all redstone functions
# True if you want this feature, false if you do not
disable-redstone: false
# This completely disables all physics for blocks
disable-physics: true
disable-gravity-physics: false
# Disables all types of explosions
# EX: creepers, tnt, end crystals, etc.
disable-explosions: true
# Prevents pesky peers pulverizing produce
# Prevent people from trampling your crops and ruining
# your soil
disable-soil-trample: true
# Disables leaves from vanishing when they are not
# nearby any logs
disable-leaves-decay: true
fix-attackspeed: false
# Prevent the dragon egg from teleporting away
prevent-dragon-egg-teleport: true
# Determines if players will be sent messages such as
# "You do not have permission for this command"
# This is useful for when you do not want to give away what
# plugins exist on your server.
send-error-messages: true
+91
View File
@@ -0,0 +1,91 @@
name: Builders-Utilities
version: "${version}"
api-version: 1.13
main: net.arcaniax.buildersutilities.Main
authors: [ Ktar5, Arcaniax ]
website: "https://www.spigotmc.org/resources/42361/"
commands:
bu:
buildersutils:
builders:
utils:
util:
banner:
description: opens banner creator
aliases: bm
permission: builders.util.banner
armorcolor:
description: opens armor color creator
aliases: color
permission: builders.util.color
nc:
aliases: noclip
description: Toggles NoClip.
permission: builders.util.noclip
af:
aliases: advfly
description: Toggles Advanced fly.
permission: builders.util.advancedfly
n:
aliases: nv
description: Toggles Nightvision.
permission: builders.util.nightvision
/1:
description: alias
permission: builders.util.aliases
/2:
description: alias
permission: builders.util.aliases
/r:
description: alias
permission: builders.util.aliases
/s:
description: alias
permission: builders.util.aliases
/c:
description: alias
permission: builders.util.aliases
/f:
description: alias
permission: builders.util.aliases
/pa:
description: alias
permission: builders.util.aliases
/derot:
description: alias
permission: builders.util.aliases
/twist:
description: alias
/scale:
description: alias
permission: builders.util.aliases
/copy:
description: alias
permission: builders.util.aliases
butil:
description: alias
aliases: bu
permission: builders.util.gui
/cuboid:
description: alias
aliases: /cub
permission: builders.util.aliases
/flip:
description: alias
permission: builders.util.aliases
/convex:
description: alias
aliases: /con
permission: builders.util.aliases
blocks:
description: Opens secret blocks menu
aliases: secretblocks
permission: builders.util.secretblocks
ws:
description: alias
permission: builders.util.aliases
fs:
description: alias
permission: builders.util.aliases
help:
permission: builders.util.help