Update from Git Manager GUI
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import mviper.plugin.hotels.core.commands.CommandDelegator;
|
||||
import mviper.plugin.hotels.core.exceptions.HotelsException;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandListener implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
try {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
|
||||
if (args.length == 0) {
|
||||
CommandDelegator.delegate("", new String[0], player);
|
||||
} else {
|
||||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
CommandDelegator.delegate(args[0], subArgs, player);
|
||||
}
|
||||
} catch (HotelsException he) {
|
||||
Messaging.send(he.getMessage(), sender);
|
||||
if (he.isPrintCommandUsage() && he.getCommandUsage() != null) {
|
||||
Messaging.send(he.getCommandUsage(), sender);
|
||||
}
|
||||
if (he.isPrintStackTrace()) {
|
||||
he.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
|
||||
if (args.length == 0) {
|
||||
return new ArrayList<>();
|
||||
} else if (args.length == 1) {
|
||||
return CommandDelegator.getPrimaryCommandLabels();
|
||||
} else {
|
||||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
return CommandDelegator.tabComplete(args[0], subArgs, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
src/main/java/mviper/plugin/hotels/bukkit/ConfigAdapter.java
Normal file
46
src/main/java/mviper/plugin/hotels/bukkit/ConfigAdapter.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Handles loading and saving of YAML files
|
||||
*/
|
||||
public class ConfigAdapter {
|
||||
|
||||
//TODO implement methods
|
||||
|
||||
/**
|
||||
* Extracts a yml file from resources to the plugin folder
|
||||
* @param name The name of the file in the resources folder
|
||||
*/
|
||||
void setupConfig(String name) {
|
||||
|
||||
}
|
||||
|
||||
HotelsConfiguration getConfig(Path path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
void saveConfig(HotelsConfiguration config) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import mviper.plugin.hotels.core.exceptions.BruhMoment;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class EconomyAdapter {
|
||||
|
||||
private Economy economy;
|
||||
|
||||
public void initialise() {
|
||||
RegisteredServiceProvider<Economy> registration =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (registration == null) {
|
||||
throw new BruhMoment(); // TODO make and handle this exception properly
|
||||
}
|
||||
|
||||
economy = registration.getProvider();
|
||||
}
|
||||
|
||||
public String getCurrencyNameSingular() {
|
||||
return economy.currencyNameSingular();
|
||||
}
|
||||
|
||||
public String getCurrencyNamePlural() {
|
||||
return economy.currencyNamePlural();
|
||||
}
|
||||
|
||||
public BigDecimal getBalance(Player player) {
|
||||
return BigDecimal.valueOf(economy.getBalance(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to withdraw amount from player account
|
||||
* @param player Player whose account we will be acting on
|
||||
* @param amount Amount to withdraw
|
||||
* @return Whether we were able to withdraw amount
|
||||
*/
|
||||
public boolean withdrawAmount(Player player, BigDecimal amount) {
|
||||
return economy.withdrawPlayer(player, amount.doubleValue()).transactionSuccess();
|
||||
}
|
||||
|
||||
public String formatCurrency(BigDecimal amount) {
|
||||
return economy.format(amount.doubleValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* YAML Configuration handler
|
||||
*/
|
||||
public class HotelsConfiguration {
|
||||
private final YamlConfiguration config;
|
||||
|
||||
public HotelsConfiguration(YamlConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public String getCurrentPath() {
|
||||
return config.getCurrentPath();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return config.getName();
|
||||
}
|
||||
|
||||
public Set<String> getKeys(boolean deep) {
|
||||
return config.getKeys(deep);
|
||||
}
|
||||
|
||||
public Map<String, Object> getValues(boolean deep) {
|
||||
return config.getValues(deep);
|
||||
}
|
||||
|
||||
public boolean contains(String path) {
|
||||
return config.contains(path);
|
||||
}
|
||||
|
||||
public boolean contains(String path, boolean ignoreDefault) {
|
||||
return config.contains(path, ignoreDefault);
|
||||
}
|
||||
|
||||
public boolean isSet(String path) {
|
||||
return config.isSet(path);
|
||||
}
|
||||
|
||||
public Object get(String path) {
|
||||
return config.get(path);
|
||||
}
|
||||
|
||||
public Object get(String path, Object def) {
|
||||
return config.get(path, def);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public String getString(String path, String def) {
|
||||
return config.getString(path, def);
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
return config.getDouble(path, def);
|
||||
}
|
||||
|
||||
public long getLong(String path) {
|
||||
return config.getLong(path);
|
||||
}
|
||||
|
||||
public long getLong(String path, long def) {
|
||||
return config.getLong(path, def);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getList(String path) {
|
||||
return (List<T>) config.getList(path);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getList(String path, List<T> def) {
|
||||
return (List<T>) config.getList(path, def);
|
||||
}
|
||||
|
||||
public List<String> getStringList(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerList(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBooleanList(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubleList(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
|
||||
public List<Float> getFloatList(String path) {
|
||||
return config.getFloatList(path);
|
||||
}
|
||||
|
||||
public List<Long> getLongList(String path) {
|
||||
return config.getLongList(path);
|
||||
}
|
||||
|
||||
public List<Byte> getByteList(String path) {
|
||||
return config.getByteList(path);
|
||||
}
|
||||
|
||||
public List<Character> getCharacterList(String path) {
|
||||
return config.getCharacterList(path);
|
||||
}
|
||||
|
||||
public List<Short> getShortList(String path) {
|
||||
return config.getShortList(path);
|
||||
}
|
||||
|
||||
public <T> T getObject(String path, Class<T> clazz) {
|
||||
return config.getObject(path, clazz);
|
||||
}
|
||||
|
||||
public <T> T getObject(String path, Class<T> clazz, T def) {
|
||||
return config.getObject(path, clazz, def);
|
||||
}
|
||||
}
|
||||
70
src/main/java/mviper/plugin/hotels/bukkit/HotelsMain.java
Normal file
70
src/main/java/mviper/plugin/hotels/bukkit/HotelsMain.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import mviper.plugin.hotels.core.database.HotelsQuery;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class HotelsMain extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Hotels v" + getDescription().getVersion() + " has been enabled");
|
||||
|
||||
// Initialize bstats
|
||||
setupMetrics();
|
||||
|
||||
PluginCommand hotelsCommand = getCommand("hotels");
|
||||
CommandListener commandListener = new CommandListener();
|
||||
if (hotelsCommand != null) {
|
||||
hotelsCommand.setExecutor(commandListener);
|
||||
hotelsCommand.setTabCompleter(commandListener);
|
||||
}
|
||||
|
||||
CompletableFuture.runAsync(this::loadJPA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
unloadJPA();
|
||||
getLogger().info("Hotels v" + getDescription().getVersion() + " has been disabled");
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
Metrics metrics = new Metrics(this, 29264);
|
||||
getLogger().info("bstats metrics initialized");
|
||||
}
|
||||
|
||||
private void loadJPA() {
|
||||
// For JPA classloader to work correctly
|
||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
||||
HotelsQuery.initialise();
|
||||
getLogger().info("Loaded JPA Connection");
|
||||
}
|
||||
|
||||
private void unloadJPA() {
|
||||
HotelsQuery.closeEntityManagerFactory();
|
||||
}
|
||||
}
|
||||
66
src/main/java/mviper/plugin/hotels/bukkit/Messaging.java
Normal file
66
src/main/java/mviper/plugin/hotels/bukkit/Messaging.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class Messaging {
|
||||
|
||||
private Messaging() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player, or console if null
|
||||
* @param message Message to send
|
||||
* @param player Player the message should be sent to
|
||||
*/
|
||||
public static void send(String message, Player player) {
|
||||
if (player != null) {
|
||||
player.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getLogger().info(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void send(String message, CommandSender sender) {
|
||||
if (sender instanceof Player player) {
|
||||
send(message, player);
|
||||
} else {
|
||||
send(message, (Player) null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a debug message to a player, if debug is enabled
|
||||
* @param message Message to send
|
||||
* @param player Player the message should be sent to
|
||||
*/
|
||||
public static void debug(String message, Player player) {
|
||||
//TODO if debug enabled
|
||||
send(prependDebug(message), player);
|
||||
}
|
||||
|
||||
private static String prependDebug(String message) {
|
||||
return "[DEBUG] " + message;
|
||||
}
|
||||
}
|
||||
16
src/main/java/mviper/plugin/hotels/bukkit/Utilities.java
Normal file
16
src/main/java/mviper/plugin/hotels/bukkit/Utilities.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package mviper.plugin.hotels.bukkit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Utilities {
|
||||
|
||||
private Utilities() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
public static UUID worldNameToId(String name) {
|
||||
org.bukkit.World world = Bukkit.getWorld(name);
|
||||
return world != null ? world.getUID() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import mviper.plugin.hotels.bukkit.Messaging;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgumentOptionality;
|
||||
import mviper.plugin.hotels.core.commands.subcommands.CreateHotelCommand;
|
||||
import mviper.plugin.hotels.core.commands.subcommands.HotelsHelpCommand;
|
||||
import mviper.plugin.hotels.core.commands.subcommands.ListAllHotelsCommand;
|
||||
import mviper.plugin.hotels.core.commands.subcommands.ListHotelsInWorldCommand;
|
||||
import mviper.plugin.hotels.core.exceptions.BruhMoment;
|
||||
import mviper.plugin.hotels.core.exceptions.HotelsException;
|
||||
import mviper.plugin.hotels.core.exceptions.NoPermissionException;
|
||||
import mviper.plugin.hotels.core.exceptions.NotEnoughArgumentsException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Delegates hotels subcommands to correct handler class
|
||||
*/
|
||||
public final class CommandDelegator {
|
||||
|
||||
private static final Map<String, Set<HotelsCommand>> hotelsCommands = new HashMap<>();
|
||||
private static final List<String> primaryCommands = new ArrayList<>();
|
||||
|
||||
// primary alias of each subcommand
|
||||
public static List<String> getPrimaryCommandLabels() {
|
||||
return new ArrayList<>(primaryCommands);
|
||||
}
|
||||
|
||||
static {
|
||||
// Various versions of the same command with different arguments are grouped together
|
||||
Set<Set<HotelsCommand>> sets = ImmutableSet.of(
|
||||
ImmutableSet.of(new ListHotelsInWorldCommand(), new ListAllHotelsCommand()), // sort by highest amount of args first
|
||||
ImmutableSet.of(new CreateHotelCommand()),
|
||||
ImmutableSet.of(new HotelsHelpCommand())
|
||||
);
|
||||
|
||||
for (Set<HotelsCommand> set : sets) {
|
||||
HotelsCommand firstCommand = set.iterator().next();
|
||||
String[] labels = firstCommand.getLabels();
|
||||
primaryCommands.add(labels[0]);
|
||||
|
||||
for (String label : labels) {
|
||||
hotelsCommands.put(label, set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private CommandDelegator() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
public static void delegate(String subcommand, String[] args, Player player) {
|
||||
Messaging.send("Subcommand: " + subcommand, player);
|
||||
|
||||
if (hotelsCommands.containsKey(subcommand)) {
|
||||
|
||||
Set<HotelsCommand> hotelsCommandSet = hotelsCommands.get(subcommand);
|
||||
//Go through this set in order, and only throw no permission error if none can be run
|
||||
|
||||
boolean ranSuccessfully = false;
|
||||
HotelsException lastException = new BruhMoment();
|
||||
|
||||
if (hotelsCommandSet == null) {
|
||||
throw lastException;
|
||||
}
|
||||
|
||||
for (HotelsCommand hotelsCommand : hotelsCommandSet) {
|
||||
try {
|
||||
hotelsCommand.acceptAndExecute(args, player); //Try to run command
|
||||
ranSuccessfully = true; //If it didn't go to catch clause, the command ran, so we can break here
|
||||
break;
|
||||
} catch (NotEnoughArgumentsException e) {
|
||||
lastException = e; //Save last thrown exception, to show user most relevant error
|
||||
} catch (NoPermissionException e) {
|
||||
lastException = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ranSuccessfully) {
|
||||
throw lastException;
|
||||
}
|
||||
} else {
|
||||
Messaging.send("Hotels subcommand not recognised!", player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide suggestions for tab complete feature
|
||||
*/
|
||||
public static List<String> tabComplete(String subcommand, String[] args, Player player) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
if (!hotelsCommands.containsKey(subcommand)) {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
Set<HotelsCommand> hotelsCommandSet = hotelsCommands.get(subcommand);
|
||||
if (hotelsCommandSet == null) {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
for (HotelsCommand hotelsCommand : hotelsCommandSet) {
|
||||
// match each provided argument as far as possible
|
||||
var argument = hotelsCommand.nextMissingArgument(args);
|
||||
if (argument == null) {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
return switch (argument.getOptionality()) {
|
||||
case PLAYER_NAME -> Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
case WORLD_NAME -> Bukkit.getWorlds().stream()
|
||||
.map(org.bukkit.World::getName)
|
||||
.collect(Collectors.toList());
|
||||
default -> suggestions;
|
||||
};
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands;
|
||||
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgument;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgumentOptionality;
|
||||
import mviper.plugin.hotels.core.exceptions.NoPermissionException;
|
||||
import mviper.plugin.hotels.core.exceptions.NotEnoughArgumentsException;
|
||||
import mviper.plugin.hotels.core.permissions.HotelsPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* A subcommand of the /hotels command
|
||||
*/
|
||||
public abstract class HotelsCommand {
|
||||
private final String[] labels;
|
||||
private final Set<HotelsCommandArgument> arguments;
|
||||
private final HotelsPermission permission;
|
||||
|
||||
public HotelsCommand(String[] labels, Set<HotelsCommandArgument> arguments, HotelsPermission permission) {
|
||||
this.labels = labels;
|
||||
this.arguments = arguments;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has permission to execute the command
|
||||
* @param player Player executing the command
|
||||
* @return Whether the player can execute this command
|
||||
*/
|
||||
private boolean hasPermission(Player player) {
|
||||
return permission.checkPermission(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets next argument the subcommand is expecting
|
||||
*/
|
||||
public HotelsCommandArgument nextMissingArgument(String[] args) {
|
||||
Iterator<HotelsCommandArgument> argumentsIterator = arguments.iterator();
|
||||
HotelsCommandArgument argument = null;
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (argumentsIterator.hasNext()) {
|
||||
argument = argumentsIterator.next();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts subcommand arguments and sets them accordingly
|
||||
* @param args The arguments for the subcommand, excluding the subcommand label itself
|
||||
* @param player The player who sent the command, for inferring of optional arguments
|
||||
*/
|
||||
private void acceptArguments(String[] args, Player player) {
|
||||
Iterator<HotelsCommandArgument> argumentsIterator = arguments.iterator();
|
||||
int argIndex = 0;
|
||||
|
||||
while (argumentsIterator.hasNext()) {
|
||||
HotelsCommandArgument argument = argumentsIterator.next();
|
||||
|
||||
if (argIndex < args.length) {
|
||||
argument.setValue(args[argIndex]);
|
||||
argIndex++;
|
||||
} else {
|
||||
// Argument must be inferred from player
|
||||
if (player == null) {
|
||||
throw new NotEnoughArgumentsException(getUsage());
|
||||
}
|
||||
|
||||
switch (argument.getOptionality()) {
|
||||
case PLAYER_NAME -> argument.setValue(player.getName());
|
||||
case WORLD_NAME -> argument.setValue(player.getWorld().getName());
|
||||
default -> throw new NotEnoughArgumentsException(getUsage());
|
||||
}
|
||||
}
|
||||
System.out.println("Args value " + argument.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts subcommand arguments and executes the command
|
||||
* @param args The arguments for the subcommand, excluding the subcommand label itself
|
||||
* @param player The player who sent the command, for optional arguments inferring
|
||||
*/
|
||||
public void acceptAndExecute(String[] args, Player player) {
|
||||
acceptArguments(args, player);
|
||||
if (hasPermission(player)) {
|
||||
CompletableFuture.runAsync(() -> execute(player));
|
||||
} else {
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the subcommand
|
||||
*/
|
||||
public abstract void execute(Player player);
|
||||
|
||||
protected HotelsCommandArgument getArgument(int index) {
|
||||
return arguments.toArray(new HotelsCommandArgument[0])[index];
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
StringBuilder usageString = new StringBuilder("/ht ");
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
usageString.append(labels[i]);
|
||||
if (labels.length > 1 && i < labels.length - 1) {
|
||||
usageString.append("|");
|
||||
}
|
||||
}
|
||||
|
||||
for (HotelsCommandArgument arg : arguments) {
|
||||
if (arg.getOptionality() == HotelsCommandArgumentOptionality.FALSE) {
|
||||
usageString.append(" <").append(arg.getSuggestion()).append(">");
|
||||
} else {
|
||||
usageString.append(" [").append(arg.getSuggestion()).append("]");
|
||||
}
|
||||
}
|
||||
|
||||
return usageString.toString();
|
||||
}
|
||||
|
||||
public String[] getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public Set<HotelsCommandArgument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public HotelsPermission getPermission() {
|
||||
return permission;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.arguments;
|
||||
|
||||
/**
|
||||
* Represents an argument to a subcommand of the /hotels command
|
||||
*/
|
||||
public class HotelsCommandArgument {
|
||||
private final HotelsCommandArgumentOptionality optionality;
|
||||
/**
|
||||
* Label suggested if the command syntax is entered wrongly
|
||||
*/
|
||||
private final String suggestion;
|
||||
|
||||
/**
|
||||
* The input the user entered for this argument
|
||||
*/
|
||||
private String value;
|
||||
|
||||
public HotelsCommandArgument(HotelsCommandArgumentOptionality optionality, String suggestion) {
|
||||
this.optionality = optionality;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status, whether an input was given and the argument is optional
|
||||
* @return The status, depending on the input and optionality
|
||||
*/
|
||||
public HotelsCommandArgumentStatus getStatus() {
|
||||
if (hasInput()) {
|
||||
return HotelsCommandArgumentStatus.FULL;
|
||||
} else if (optionality == HotelsCommandArgumentOptionality.TRUE) {
|
||||
return HotelsCommandArgumentStatus.IGNORE;
|
||||
} else {
|
||||
return HotelsCommandArgumentStatus.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasInput() {
|
||||
return value != null && !value.isEmpty();
|
||||
}
|
||||
|
||||
public HotelsCommandArgumentOptionality getOptionality() {
|
||||
return optionality;
|
||||
}
|
||||
|
||||
public String getSuggestion() {
|
||||
return suggestion;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.arguments;
|
||||
|
||||
/**
|
||||
* Whether a HotelsCommandArgument is optional, and what kind of optionality
|
||||
*/
|
||||
public enum HotelsCommandArgumentOptionality {
|
||||
/**
|
||||
* The argument is optional
|
||||
*/
|
||||
TRUE,
|
||||
/**
|
||||
* The argument is not optional
|
||||
*/
|
||||
FALSE,
|
||||
/**
|
||||
* The argument is optional for player as it can be inferred
|
||||
*/
|
||||
PLAYER_NAME,
|
||||
/**
|
||||
* The argument is optional for players as it can be inferred
|
||||
*/
|
||||
WORLD_NAME
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package mviper.plugin.hotels.core.commands.arguments;
|
||||
|
||||
/**
|
||||
* Defines certain requirements a hotels subcommand argument must meet before being run
|
||||
* These include being owner or renter of the specified room or hotel etc.
|
||||
*/
|
||||
public class HotelsCommandArgumentRequirements {
|
||||
private final HotelsCommandArgumentRequirementsEnum requirement;
|
||||
|
||||
public HotelsCommandArgumentRequirements(HotelsCommandArgumentRequirementsEnum requirement) {
|
||||
this.requirement = requirement;
|
||||
}
|
||||
|
||||
public HotelsCommandArgumentRequirementsEnum getRequirement() {
|
||||
return requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package mviper.plugin.hotels.core.commands.arguments;
|
||||
|
||||
public enum HotelsCommandArgumentRequirementsEnum {
|
||||
OWNER, RENTER, HELPER, FRIEND
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.arguments;
|
||||
|
||||
/**
|
||||
* The current status of a HotelsCommandArgument
|
||||
*/
|
||||
public enum HotelsCommandArgumentStatus {
|
||||
/**
|
||||
* An input was given
|
||||
*/
|
||||
FULL,
|
||||
/**
|
||||
* No input given, and it is required
|
||||
*/
|
||||
EMPTY,
|
||||
/**
|
||||
* Input not given but not required
|
||||
*/
|
||||
IGNORE
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.subcommands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import mviper.plugin.hotels.core.commands.HotelsCommand;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgument;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgumentOptionality;
|
||||
import mviper.plugin.hotels.core.events.HotelCreateEvent;
|
||||
import mviper.plugin.hotels.core.exceptions.InvalidHotelException;
|
||||
import mviper.plugin.hotels.core.exceptions.PlayerOnlyException;
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import mviper.plugin.hotels.core.hotel.HotelOwner;
|
||||
import mviper.plugin.hotels.core.permissions.HotelsPermission;
|
||||
import mviper.plugin.hotels.core.regions.HotelRegion;
|
||||
import mviper.plugin.hotels.core.regions.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CreateHotelCommand extends HotelsCommand {
|
||||
|
||||
public CreateHotelCommand() {
|
||||
super(
|
||||
new String[]{"create", "c"},
|
||||
ImmutableSet.of(new HotelsCommandArgument(HotelsCommandArgumentOptionality.FALSE, "name")),
|
||||
new HotelsPermission("hotels.create")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player) {
|
||||
if (player == null) {
|
||||
throw new PlayerOnlyException();
|
||||
}
|
||||
|
||||
String hotelName = getArgument(0).getValue();
|
||||
if (hotelName == null) {
|
||||
throw new InvalidHotelException();
|
||||
}
|
||||
|
||||
var world = player.getWorld();
|
||||
|
||||
player.sendMessage("Creating hotel " + hotelName);
|
||||
|
||||
// TODO PRECONDITIONS:
|
||||
// player must have a region selected
|
||||
// region must not intersect already existing hotel regions
|
||||
// must not intersect regions with custom flag (no hotels)
|
||||
// they must have enough money to create hotel, (money scaling with size of region?)
|
||||
// must not own more than max hotels owned
|
||||
|
||||
HotelOwner hotelOwner = new HotelOwner(player.getUniqueId());
|
||||
Hotel hotel = new Hotel(hotelOwner, world.getUID().toString(), hotelName);
|
||||
String hotelId = hotel.getId().toString();
|
||||
ProtectedRegion protectedRegion = RegionManager.getProtectedRegion(player, hotelId);
|
||||
hotel.setHotelRegion(new HotelRegion(BukkitAdapter.adapt(world), hotelId, protectedRegion));
|
||||
|
||||
new HotelCreateEvent(hotel).call();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.subcommands;
|
||||
|
||||
import mviper.plugin.hotels.bukkit.Messaging;
|
||||
import mviper.plugin.hotels.core.commands.CommandDelegator;
|
||||
import mviper.plugin.hotels.core.commands.HotelsCommand;
|
||||
import mviper.plugin.hotels.core.permissions.HotelsPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class HotelsHelpCommand extends HotelsCommand {
|
||||
|
||||
public HotelsHelpCommand() {
|
||||
super(
|
||||
new String[]{"help", ""},
|
||||
Collections.emptySet(),
|
||||
new HotelsPermission("hotels.help")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player) {
|
||||
for (String label : CommandDelegator.getPrimaryCommandLabels()) {
|
||||
Messaging.send(label, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package mviper.plugin.hotels.core.commands.subcommands;
|
||||
|
||||
import mviper.plugin.hotels.bukkit.Messaging;
|
||||
import mviper.plugin.hotels.core.commands.HotelsCommand;
|
||||
import mviper.plugin.hotels.core.database.HotelsQuery;
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import mviper.plugin.hotels.core.permissions.HotelsPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ListAllHotelsCommand extends HotelsCommand {
|
||||
|
||||
public ListAllHotelsCommand() {
|
||||
super(
|
||||
new String[]{"hotellist", "hlist", "list"},
|
||||
new LinkedHashSet<>(),
|
||||
new HotelsPermission("hotels.hotellist.all")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player) {
|
||||
List<Hotel> resultList = HotelsQuery.getAll(Hotel.class);
|
||||
|
||||
if (resultList.isEmpty()) {
|
||||
Messaging.send("No hotels found at all!", player);
|
||||
} else {
|
||||
for (Hotel hotel : resultList) {
|
||||
Messaging.send("Hotel: " + hotel.getHotelName(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.commands.subcommands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import mviper.plugin.hotels.bukkit.Messaging;
|
||||
import mviper.plugin.hotels.bukkit.Utilities;
|
||||
import mviper.plugin.hotels.core.commands.HotelsCommand;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgument;
|
||||
import mviper.plugin.hotels.core.commands.arguments.HotelsCommandArgumentOptionality;
|
||||
import mviper.plugin.hotels.core.database.HotelsQuery;
|
||||
import mviper.plugin.hotels.core.exceptions.WorldNonExistentException;
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import mviper.plugin.hotels.core.permissions.HotelsPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Lists the hotels in all/given world(s)
|
||||
*/
|
||||
public class ListHotelsInWorldCommand extends HotelsCommand {
|
||||
|
||||
public ListHotelsInWorldCommand() {
|
||||
super(
|
||||
new String[]{"hotellist", "hlist", "list"},
|
||||
ImmutableSet.of(new HotelsCommandArgument(HotelsCommandArgumentOptionality.WORLD_NAME, "world")),
|
||||
new HotelsPermission("hotels.hotellist.world")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player) {
|
||||
String worldName = getArgument(0).getValue();
|
||||
if (worldName == null) {
|
||||
throw new WorldNonExistentException(getUsage());
|
||||
}
|
||||
|
||||
UUID worldId = Utilities.worldNameToId(worldName);
|
||||
if (worldId == null) {
|
||||
throw new WorldNonExistentException(getUsage());
|
||||
}
|
||||
|
||||
String queryString = "SELECT h FROM Hotel h WHERE hotelWorldId='" + worldId.toString() + "'";
|
||||
List<Hotel> resultList = HotelsQuery.runSelectQuery(queryString, Hotel.class);
|
||||
|
||||
if (resultList.isEmpty()) {
|
||||
Messaging.send("No hotels found in this world!", player);
|
||||
} else {
|
||||
for (Hotel hotel : resultList) {
|
||||
Messaging.send("Hotel: " + hotel.getHotelName(), player); //TODO make pages when too many results
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.database;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
import java.util.List;
|
||||
|
||||
public final class HotelsQuery {
|
||||
|
||||
private static EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private HotelsQuery() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
public static void initialise() {
|
||||
entityManagerFactory = Persistence.createEntityManagerFactory("HotelsPU");
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
return entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
public static void closeEntityManagerFactory() {
|
||||
entityManagerFactory.close();
|
||||
}
|
||||
|
||||
public static <T> List<T> getAll(Class<T> clazz) {
|
||||
String className = clazz.getSimpleName();
|
||||
String queryString = "SELECT a FROM " + className + " a";
|
||||
return runSelectQuery(queryString, clazz);
|
||||
}
|
||||
|
||||
public static <T> List<T> runSelectQuery(String typedQuery, Class<T> clazz) {
|
||||
EntityManager entityManager = getEntityManager();
|
||||
List<T> resultList = entityManager.createQuery(typedQuery, clazz).getResultList();
|
||||
entityManager.close();
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.database;
|
||||
|
||||
import mviper.plugin.hotels.core.exceptions.WorldNonExistentException;
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import mviper.plugin.hotels.core.hotel.HotelOwner;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import java.util.*;
|
||||
|
||||
public final class QueryTest {
|
||||
|
||||
private QueryTest() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
public static List<Hotel> getAllHotels() {
|
||||
return HotelsQuery.runSelectQuery("SELECT h FROM Hotel h", Hotel.class);
|
||||
}
|
||||
|
||||
public static List<HotelOwner> getAllOwners() {
|
||||
return HotelsQuery.runSelectQuery("SELECT o FROM HotelOwner o", HotelOwner.class);
|
||||
}
|
||||
|
||||
public static void addOwner() {
|
||||
HotelOwner owner = new HotelOwner(UUID.randomUUID());
|
||||
EntityManager entityManager = HotelsQuery.getEntityManager();
|
||||
EntityTransaction transaction = entityManager.getTransaction();
|
||||
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.persist(owner);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
entityManager.close();
|
||||
}
|
||||
|
||||
public static void addHotel() {
|
||||
HotelOwner owner = new HotelOwner(UUID.randomUUID());
|
||||
World world = Bukkit.getWorld("world");
|
||||
if (world == null) {
|
||||
throw new WorldNonExistentException("test");
|
||||
}
|
||||
|
||||
Hotel hotel = new Hotel(
|
||||
owner,
|
||||
world.getUID().toString(),
|
||||
"Test"
|
||||
);
|
||||
|
||||
EntityManager entityManager = HotelsQuery.getEntityManager();
|
||||
EntityTransaction transaction = entityManager.getTransaction();
|
||||
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.persist(owner);
|
||||
entityManager.persist(hotel);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
entityManager.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.events;
|
||||
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
|
||||
public class HotelCreateEvent extends HotelsEvent {
|
||||
private Hotel hotel;
|
||||
|
||||
public HotelCreateEvent(Hotel hotel) {
|
||||
this.hotel = hotel;
|
||||
}
|
||||
|
||||
public Hotel getHotel() {
|
||||
return hotel;
|
||||
}
|
||||
|
||||
public void setHotel(Hotel hotel) {
|
||||
this.hotel = hotel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class HotelsEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getServer().getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
/**
|
||||
* For when there shouldn't be an exception thrown
|
||||
*/
|
||||
public class BruhMoment extends HotelsException {
|
||||
public BruhMoment() {
|
||||
super("Unknown error has occurred", null, false, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class HotelsException extends RuntimeException {
|
||||
private final String commandUsage;
|
||||
private final boolean printCommandUsage;
|
||||
private final boolean printStackTrace;
|
||||
|
||||
public HotelsException(String message, String commandUsage, boolean printCommandUsage, boolean printStackTrace) {
|
||||
super(message);
|
||||
this.commandUsage = commandUsage;
|
||||
this.printCommandUsage = printCommandUsage;
|
||||
this.printStackTrace = printStackTrace;
|
||||
}
|
||||
|
||||
public HotelsException(String message) {
|
||||
this(message, null, true, false);
|
||||
}
|
||||
|
||||
public HotelsException(String message, String commandUsage) {
|
||||
this(message, commandUsage, true, false);
|
||||
}
|
||||
|
||||
public String getCommandUsage() {
|
||||
return commandUsage;
|
||||
}
|
||||
|
||||
public boolean isPrintCommandUsage() {
|
||||
return printCommandUsage;
|
||||
}
|
||||
|
||||
public boolean isPrintStackTrace() {
|
||||
return printStackTrace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class InvalidHotelException extends HotelsException {
|
||||
public InvalidHotelException() {
|
||||
super("Specified hotel is not valid!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class InvalidRegionException extends HotelsException {
|
||||
public InvalidRegionException() {
|
||||
super("Region is not valid!", null, false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class NoArgumentsException extends HotelsException {
|
||||
public NoArgumentsException(String commandUsage) {
|
||||
super("No arguments!", commandUsage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class NoPermissionException extends HotelsException {
|
||||
public NoPermissionException() {
|
||||
super("No permission!", null, false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class NotEnoughArgumentsException extends HotelsException {
|
||||
public NotEnoughArgumentsException(String commandUsage) {
|
||||
super("Not enough arguments!", commandUsage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class PlayerOnlyException extends HotelsException {
|
||||
public PlayerOnlyException() {
|
||||
super("This command can only be run by a player", null, false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class WorldGuardException extends HotelsException {
|
||||
public WorldGuardException() {
|
||||
super("WorldGuard error!", null, true, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.exceptions;
|
||||
|
||||
public class WorldNonExistentException extends HotelsException {
|
||||
public WorldNonExistentException(String commandUsage) {
|
||||
super("Specified world does not exist!", commandUsage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.homes;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractHome {
|
||||
|
||||
@Basic(optional = false)
|
||||
private int x;
|
||||
|
||||
@Basic(optional = false)
|
||||
private int y;
|
||||
|
||||
@Basic(optional = false)
|
||||
private int z;
|
||||
|
||||
@Basic(optional = false)
|
||||
private float pitch;
|
||||
|
||||
@Basic(optional = false)
|
||||
private float yaw;
|
||||
|
||||
public AbstractHome(int x, int y, int z, float pitch, float yaw) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
}
|
||||
50
src/main/java/mviper/plugin/hotels/core/homes/HotelHome.java
Normal file
50
src/main/java/mviper/plugin/hotels/core/homes/HotelHome.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.homes;
|
||||
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class HotelHome extends AbstractHome {
|
||||
|
||||
@OneToOne(optional = false)
|
||||
private final Hotel hotel;
|
||||
|
||||
@Id
|
||||
private final String hotelId;
|
||||
|
||||
public HotelHome(Hotel hotel, int x, int y, int z, float pitch, float yaw) {
|
||||
super(x, y, z, pitch, yaw);
|
||||
this.hotel = hotel;
|
||||
this.hotelId = hotel.getId().toString();
|
||||
}
|
||||
|
||||
public Hotel getHotel() {
|
||||
return hotel;
|
||||
}
|
||||
|
||||
public String getHotelId() {
|
||||
return hotelId;
|
||||
}
|
||||
}
|
||||
51
src/main/java/mviper/plugin/hotels/core/homes/RoomHome.java
Normal file
51
src/main/java/mviper/plugin/hotels/core/homes/RoomHome.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.homes;
|
||||
|
||||
import mviper.plugin.hotels.core.room.Room;
|
||||
import java.util.UUID;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class RoomHome extends AbstractHome {
|
||||
|
||||
@OneToOne(optional = false)
|
||||
private final Room room;
|
||||
|
||||
@Id
|
||||
private final UUID roomId;
|
||||
|
||||
public RoomHome(Room room, int x, int y, int z, float pitch, float yaw) {
|
||||
super(x, y, z, pitch, yaw);
|
||||
this.room = room;
|
||||
this.roomId = room.getId();
|
||||
}
|
||||
|
||||
public Room getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public UUID getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
}
|
||||
131
src/main/java/mviper/plugin/hotels/core/hotel/Hotel.java
Normal file
131
src/main/java/mviper/plugin/hotels/core/hotel/Hotel.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.hotel;
|
||||
|
||||
import mviper.plugin.hotels.core.homes.HotelHome;
|
||||
import mviper.plugin.hotels.core.regions.HotelRegion;
|
||||
import mviper.plugin.hotels.core.room.Room;
|
||||
import java.util.*;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Represents a Hotel object
|
||||
*/
|
||||
@Entity
|
||||
public class Hotel {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private UUID id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
private HotelOwner hotelOwner;
|
||||
|
||||
@Basic(optional = false)
|
||||
private String hotelWorldId;
|
||||
|
||||
@Basic(optional = false)
|
||||
private String hotelName;
|
||||
|
||||
@Transient
|
||||
private HotelRegion hotelRegion;
|
||||
|
||||
@ManyToMany
|
||||
private Set<HotelHelper> hotelHelpers = new HashSet<>();
|
||||
|
||||
@OneToMany
|
||||
private Set<Room> hotelRooms = new HashSet<>();
|
||||
|
||||
@OneToOne
|
||||
private HotelHome hotelHome;
|
||||
|
||||
public Hotel() {
|
||||
}
|
||||
|
||||
public Hotel(HotelOwner hotelOwner, String hotelWorldId, String hotelName) {
|
||||
this.hotelOwner = hotelOwner;
|
||||
this.hotelWorldId = hotelWorldId;
|
||||
this.hotelName = hotelName;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public HotelOwner getHotelOwner() {
|
||||
return hotelOwner;
|
||||
}
|
||||
|
||||
public void setHotelOwner(HotelOwner hotelOwner) {
|
||||
this.hotelOwner = hotelOwner;
|
||||
}
|
||||
|
||||
public String getHotelWorldId() {
|
||||
return hotelWorldId;
|
||||
}
|
||||
|
||||
public void setHotelWorldId(String hotelWorldId) {
|
||||
this.hotelWorldId = hotelWorldId;
|
||||
}
|
||||
|
||||
public String getHotelName() {
|
||||
return hotelName;
|
||||
}
|
||||
|
||||
public void setHotelName(String hotelName) {
|
||||
this.hotelName = hotelName;
|
||||
}
|
||||
|
||||
public HotelRegion getHotelRegion() {
|
||||
return hotelRegion;
|
||||
}
|
||||
|
||||
public void setHotelRegion(HotelRegion hotelRegion) {
|
||||
this.hotelRegion = hotelRegion;
|
||||
}
|
||||
|
||||
public Set<HotelHelper> getHotelHelpers() {
|
||||
return hotelHelpers;
|
||||
}
|
||||
|
||||
public void setHotelHelpers(Set<HotelHelper> hotelHelpers) {
|
||||
this.hotelHelpers = hotelHelpers;
|
||||
}
|
||||
|
||||
public Set<Room> getHotelRooms() {
|
||||
return hotelRooms;
|
||||
}
|
||||
|
||||
public void setHotelRooms(Set<Room> hotelRooms) {
|
||||
this.hotelRooms = hotelRooms;
|
||||
}
|
||||
|
||||
public HotelHome getHotelHome() {
|
||||
return hotelHome;
|
||||
}
|
||||
|
||||
public void setHotelHome(HotelHome hotelHome) {
|
||||
this.hotelHome = hotelHome;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.hotel;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
|
||||
/**
|
||||
* Represents a hotel helper, who can build in a hotel region but cannot administer it
|
||||
*/
|
||||
@Entity
|
||||
public class HotelHelper {
|
||||
@Id
|
||||
private final UUID playerId;
|
||||
|
||||
@ManyToMany
|
||||
private final Set<Hotel> hotels;
|
||||
|
||||
public HotelHelper(UUID playerId, Set<Hotel> hotels) {
|
||||
this.playerId = playerId;
|
||||
this.hotels = hotels;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public Set<Hotel> getHotels() {
|
||||
return hotels;
|
||||
}
|
||||
|
||||
public boolean add(Hotel hotel) {
|
||||
return hotels.add(hotel);
|
||||
}
|
||||
|
||||
public boolean remove(Hotel hotel) {
|
||||
return hotels.remove(hotel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.hotel;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
* Represents the owner of a hotel
|
||||
*/
|
||||
@Entity
|
||||
public class HotelOwner {
|
||||
@Id
|
||||
private UUID playerId;
|
||||
|
||||
@OneToMany
|
||||
private Set<Hotel> hotels = new HashSet<>();
|
||||
|
||||
public HotelOwner() {
|
||||
}
|
||||
|
||||
public HotelOwner(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public HotelOwner(UUID playerId, Set<Hotel> hotels) {
|
||||
this.playerId = playerId;
|
||||
this.hotels = hotels;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public void setPlayerId(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public Set<Hotel> getHotels() {
|
||||
return hotels;
|
||||
}
|
||||
|
||||
public void setHotels(Set<Hotel> hotels) {
|
||||
this.hotels = hotels;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2020 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.permissions;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Represents a checkable Hotels permission
|
||||
*/
|
||||
public class HotelsPermission {
|
||||
private final String permission;
|
||||
|
||||
public HotelsPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public boolean checkPermission(Player player) {
|
||||
return player == null || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
//TODO must include ways to check that player is owner of hotel and thus can run certain commands etc.
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.regions;
|
||||
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import mviper.plugin.hotels.core.regions.RegionManager;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Provides an abstraction for interfacing Hotel's classes with WorldGuard regions
|
||||
*/
|
||||
public abstract class AbstractRegion {
|
||||
private final World world;
|
||||
private final String id;
|
||||
private final ProtectedRegion region;
|
||||
|
||||
/**
|
||||
* For already existing regions
|
||||
* @param id The UUID of the object representing the region, i.e. a Hotel UUID
|
||||
*/
|
||||
public AbstractRegion(World world, String id) {
|
||||
this.world = world;
|
||||
this.id = id;
|
||||
this.region = RegionManager.getRegion(world, RegionManager.REGION_PREFIX + id);
|
||||
}
|
||||
|
||||
public AbstractRegion(World world, String id, ProtectedRegion region) {
|
||||
this.world = world;
|
||||
this.id = id;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
private DefaultDomain getMembers() {
|
||||
return region.getMembers();
|
||||
}
|
||||
|
||||
private DefaultDomain getOwners() {
|
||||
return region.getOwners();
|
||||
}
|
||||
|
||||
public void addMember(UUID playerId) {
|
||||
getMembers().addPlayer(playerId);
|
||||
}
|
||||
|
||||
public void removeMember(UUID playerId) {
|
||||
getMembers().removePlayer(playerId);
|
||||
}
|
||||
|
||||
public void addOwner(UUID playerId) {
|
||||
getOwners().addPlayer(playerId);
|
||||
}
|
||||
|
||||
public void removeOwner(UUID playerId) {
|
||||
getOwners().removePlayer(playerId);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ProtectedRegion getRegion() {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.regions;
|
||||
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
/**
|
||||
* Provides an abstraction for manipulating a hotel's region
|
||||
*/
|
||||
public class HotelRegion extends AbstractRegion {
|
||||
|
||||
public HotelRegion(World world, String id, ProtectedRegion region) {
|
||||
super(world, id, region);
|
||||
}
|
||||
|
||||
public HotelRegion(World world, String id) {
|
||||
super(world, id);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO this must not actually try to get the region but rather represent it
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.regions;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.managers.RemovalStrategy;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import mviper.plugin.hotels.core.exceptions.InvalidRegionException;
|
||||
import mviper.plugin.hotels.core.exceptions.WorldGuardException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class RegionManager {
|
||||
|
||||
public static final String REGION_PREFIX = "HOTELS_";
|
||||
|
||||
private static final WorldGuard WG_INSTANCE = WorldGuard.getInstance();
|
||||
private static final com.sk89q.worldguard.protection.regions.RegionContainer REGION_CONTAINER =
|
||||
WG_INSTANCE.getPlatform().getRegionContainer();
|
||||
private static final WorldEditPlugin worldEditPlugin =
|
||||
(WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
private RegionManager() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
private static com.sk89q.worldguard.protection.managers.RegionManager getRegionManager(World world) {
|
||||
com.sk89q.worldguard.protection.managers.RegionManager rm = REGION_CONTAINER.get(world);
|
||||
if (rm == null) {
|
||||
throw new WorldGuardException();
|
||||
}
|
||||
return rm;
|
||||
}
|
||||
|
||||
public static ProtectedRegion getRegion(World world, String id) {
|
||||
ProtectedRegion region = getRegionManager(world).getRegion(id);
|
||||
if (region == null) {
|
||||
throw new InvalidRegionException();
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
public static void addRegion(World world, ProtectedRegion region) {
|
||||
getRegionManager(world).addRegion(region);
|
||||
}
|
||||
|
||||
public static void removeRegion(World world, String id) {
|
||||
getRegionManager(world).removeRegion(id, RemovalStrategy.UNSET_PARENT_IN_CHILDREN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Protected Region from a player's selection
|
||||
* @param id The UUID of the region's object, i.e. a Hotel UUID
|
||||
*/
|
||||
public static ProtectedRegion getProtectedRegion(Player player, String id) {
|
||||
Region selection = getSelection(player);
|
||||
return toProtectedRegion(selection, id);
|
||||
}
|
||||
|
||||
public static ProtectedRegion toProtectedRegion(Region region, String id) {
|
||||
if (region instanceof CuboidRegion cuboidRegion) {
|
||||
return new ProtectedCuboidRegion(REGION_PREFIX + id,
|
||||
cuboidRegion.getMinimumPoint(), cuboidRegion.getMaximumPoint());
|
||||
} else if (region instanceof Polygonal2DRegion polygonRegion) {
|
||||
return new ProtectedPolygonalRegion(id, polygonRegion.getPoints(),
|
||||
polygonRegion.getMinimumY(), polygonRegion.getMaximumY());
|
||||
} else {
|
||||
throw new InvalidRegionException();
|
||||
}
|
||||
}
|
||||
|
||||
// WorldEdit
|
||||
private static Region getSelection(Player player) {
|
||||
try {
|
||||
return worldEditPlugin.getSession(player).getClipboard().getClipboard().getRegion();
|
||||
} catch (com.sk89q.worldedit.EmptyClipboardException e) {
|
||||
throw new InvalidRegionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.regions;
|
||||
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
* Provides an abstraction for manipulating a room's region
|
||||
*/
|
||||
public class RoomRegion extends AbstractRegion {
|
||||
|
||||
public RoomRegion(World world, String id) {
|
||||
super(world, id);
|
||||
}
|
||||
}
|
||||
187
src/main/java/mviper/plugin/hotels/core/room/Room.java
Normal file
187
src/main/java/mviper/plugin/hotels/core/room/Room.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.room;
|
||||
|
||||
import mviper.plugin.hotels.core.homes.RoomHome;
|
||||
import mviper.plugin.hotels.core.hotel.Hotel;
|
||||
import mviper.plugin.hotels.core.regions.RoomRegion;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
/**
|
||||
* Represents a room in a hotel
|
||||
*/
|
||||
@Entity
|
||||
public class Room {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
private Hotel hotel;
|
||||
|
||||
@Basic(optional = false)
|
||||
private int roomNumber;
|
||||
|
||||
@Basic(optional = false)
|
||||
private long rentTime; // in minutes
|
||||
|
||||
@Basic(optional = false)
|
||||
private double cost;
|
||||
|
||||
@Basic(optional = false)
|
||||
private boolean isRoomReset;
|
||||
|
||||
@ManyToOne
|
||||
private RoomRenter renter;
|
||||
|
||||
@OneToMany
|
||||
private Set<RoomFriend> roomFriends = new HashSet<>();
|
||||
|
||||
@OneToOne
|
||||
private RoomHome roomHome;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private LocalDateTime expiryInstant;
|
||||
|
||||
@Transient
|
||||
private RoomRegion region;
|
||||
|
||||
public Room() {
|
||||
}
|
||||
|
||||
public Room(UUID id, Hotel hotel, int roomNumber, long rentTime, double cost,
|
||||
boolean isRoomReset, RoomRenter renter, Set<RoomFriend> roomFriends,
|
||||
RoomHome roomHome, LocalDateTime expiryInstant, RoomRegion region) {
|
||||
this.id = id;
|
||||
this.hotel = hotel;
|
||||
this.roomNumber = roomNumber;
|
||||
this.rentTime = rentTime;
|
||||
this.cost = cost;
|
||||
this.isRoomReset = isRoomReset;
|
||||
this.renter = renter;
|
||||
this.roomFriends = roomFriends != null ? roomFriends : new HashSet<>();
|
||||
this.roomHome = roomHome;
|
||||
this.expiryInstant = expiryInstant;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public Set<RoomFriend> getRoomFriends() {
|
||||
return roomFriends;
|
||||
}
|
||||
|
||||
public boolean addFriend(RoomFriend roomFriend) {
|
||||
return roomFriends.add(roomFriend);
|
||||
}
|
||||
|
||||
public boolean removeFriend(RoomFriend roomFriend) {
|
||||
return roomFriends.remove(roomFriend);
|
||||
}
|
||||
|
||||
public void clearFriends() {
|
||||
roomFriends.clear();
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Hotel getHotel() {
|
||||
return hotel;
|
||||
}
|
||||
|
||||
public void setHotel(Hotel hotel) {
|
||||
this.hotel = hotel;
|
||||
}
|
||||
|
||||
public int getRoomNumber() {
|
||||
return roomNumber;
|
||||
}
|
||||
|
||||
public void setRoomNumber(int roomNumber) {
|
||||
this.roomNumber = roomNumber;
|
||||
}
|
||||
|
||||
public long getRentTime() {
|
||||
return rentTime;
|
||||
}
|
||||
|
||||
public void setRentTime(long rentTime) {
|
||||
this.rentTime = rentTime;
|
||||
}
|
||||
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setCost(double cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public boolean isRoomReset() {
|
||||
return isRoomReset;
|
||||
}
|
||||
|
||||
public void setRoomReset(boolean roomReset) {
|
||||
isRoomReset = roomReset;
|
||||
}
|
||||
|
||||
public RoomRenter getRenter() {
|
||||
return renter;
|
||||
}
|
||||
|
||||
public void setRenter(RoomRenter renter) {
|
||||
this.renter = renter;
|
||||
}
|
||||
|
||||
public void setRoomFriends(Set<RoomFriend> roomFriends) {
|
||||
this.roomFriends = roomFriends;
|
||||
}
|
||||
|
||||
public RoomHome getRoomHome() {
|
||||
return roomHome;
|
||||
}
|
||||
|
||||
public void setRoomHome(RoomHome roomHome) {
|
||||
this.roomHome = roomHome;
|
||||
}
|
||||
|
||||
public LocalDateTime getExpiryInstant() {
|
||||
return expiryInstant;
|
||||
}
|
||||
|
||||
public void setExpiryInstant(LocalDateTime expiryInstant) {
|
||||
this.expiryInstant = expiryInstant;
|
||||
}
|
||||
|
||||
public RoomRegion getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(RoomRegion region) {
|
||||
this.region = region;
|
||||
}
|
||||
}
|
||||
59
src/main/java/mviper/plugin/hotels/core/room/RoomFriend.java
Normal file
59
src/main/java/mviper/plugin/hotels/core/room/RoomFriend.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.room;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
|
||||
/**
|
||||
* Represents a friend, who can use a room but not administer it
|
||||
*/
|
||||
@Entity
|
||||
public class RoomFriend {
|
||||
@Id
|
||||
private final UUID playerId;
|
||||
|
||||
@ManyToMany
|
||||
private final Set<Room> rooms;
|
||||
|
||||
public RoomFriend(UUID playerId, Set<Room> rooms) {
|
||||
this.playerId = playerId;
|
||||
this.rooms = rooms;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public Set<Room> getRooms() {
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public boolean add(Room room) {
|
||||
return rooms.add(room);
|
||||
}
|
||||
|
||||
public boolean remove(Room room) {
|
||||
return rooms.remove(room);
|
||||
}
|
||||
}
|
||||
59
src/main/java/mviper/plugin/hotels/core/room/RoomRenter.java
Normal file
59
src/main/java/mviper/plugin/hotels/core/room/RoomRenter.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Hotels Bukkit Plugin
|
||||
* Copyright (C) 2019 mviper
|
||||
* Full licence text can be found in LICENCE file
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package mviper.plugin.hotels.core.room;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
* Represents the renter of a room in a hotel
|
||||
*/
|
||||
@Entity
|
||||
public class RoomRenter {
|
||||
@Id
|
||||
private final UUID playerId;
|
||||
|
||||
@OneToMany
|
||||
private final Set<Room> rooms;
|
||||
|
||||
public RoomRenter(UUID playerId, Set<Room> rooms) {
|
||||
this.playerId = playerId;
|
||||
this.rooms = rooms;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public Set<Room> getRooms() {
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public boolean add(Room room) {
|
||||
return rooms.add(room);
|
||||
}
|
||||
|
||||
public boolean remove(Room room) {
|
||||
return rooms.remove(room);
|
||||
}
|
||||
}
|
||||
42
src/main/resources/META-INF/persistence.xml
Normal file
42
src/main/resources/META-INF/persistence.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Hotels Bukkit Plugin
|
||||
~ Copyright (C) 2019 mviper
|
||||
~ Full licence text can be found in LICENCE file
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU Affero General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
~
|
||||
-->
|
||||
|
||||
<persistence version="3.0" xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||
|
||||
<persistence-unit name="HotelsPU" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:./plugins/Hotels/database"/>
|
||||
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||
|
||||
<property name="hibernate.connection.provider_class" value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider" />
|
||||
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
|
||||
<property name="hibernate.hbm2ddl.auto" value="update" />
|
||||
<!-- <property name="show_sql" value="true"/>-->
|
||||
<!-- <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
89
src/main/resources/config.yml
Normal file
89
src/main/resources/config.yml
Normal file
@@ -0,0 +1,89 @@
|
||||
# Hotels Plugin Configuration
|
||||
# Version: 2.0.0
|
||||
# For Minecraft 1.21.x
|
||||
|
||||
# Database settings
|
||||
database:
|
||||
# Database type: h2, mysql, postgresql
|
||||
type: h2
|
||||
# H2 database file location (relative to plugin folder)
|
||||
h2-file: database
|
||||
# MySQL/PostgreSQL settings (if using external database)
|
||||
host: localhost
|
||||
port: 3306
|
||||
database: hotels
|
||||
username: root
|
||||
password: ""
|
||||
# Connection pool settings
|
||||
pool:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 2
|
||||
connection-timeout: 30000
|
||||
|
||||
# Economy settings
|
||||
economy:
|
||||
# Enable economy integration (requires Vault)
|
||||
enabled: true
|
||||
# Default currency symbol
|
||||
currency-symbol: "$"
|
||||
|
||||
# Hotel settings
|
||||
hotels:
|
||||
# Maximum number of hotels per player
|
||||
max-hotels-per-player: 5
|
||||
# Maximum number of rooms per hotel
|
||||
max-rooms-per-hotel: 50
|
||||
# Minimum distance between hotels (in blocks)
|
||||
min-hotel-distance: 100
|
||||
# Allow hotel creation in all worlds
|
||||
allow-all-worlds: true
|
||||
# Worlds where hotels are allowed (if allow-all-worlds is false)
|
||||
allowed-worlds:
|
||||
- world
|
||||
- world_nether
|
||||
- world_the_end
|
||||
|
||||
# Room settings
|
||||
rooms:
|
||||
# Default rent duration in days
|
||||
default-rent-duration: 7
|
||||
# Maximum rent duration in days
|
||||
max-rent-duration: 30
|
||||
# Minimum rent price
|
||||
min-rent-price: 10.0
|
||||
# Maximum rent price
|
||||
max-rent-price: 10000.0
|
||||
# Allow room friends
|
||||
allow-friends: true
|
||||
# Maximum number of friends per room
|
||||
max-friends-per-room: 5
|
||||
|
||||
# Region settings
|
||||
regions:
|
||||
# Minimum region size (blocks)
|
||||
min-region-size: 16
|
||||
# Maximum region size (blocks)
|
||||
max-region-size: 10000
|
||||
# Require WorldGuard region for hotel creation
|
||||
require-worldguard: true
|
||||
|
||||
# Permission settings
|
||||
permissions:
|
||||
# Use permission-based limits (overrides default limits)
|
||||
use-permission-limits: true
|
||||
|
||||
# Messages
|
||||
messages:
|
||||
# Message prefix
|
||||
prefix: "&8[&6Hotels&8]&r "
|
||||
# Enable colored messages
|
||||
colored-messages: true
|
||||
|
||||
# Debug mode
|
||||
debug: false
|
||||
|
||||
# Auto-save interval (in minutes, 0 to disable)
|
||||
auto-save-interval: 5
|
||||
|
||||
# Language (en, de, es, fr)
|
||||
language: en
|
||||
66
src/main/resources/plugin.yml
Normal file
66
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,66 @@
|
||||
main: mviper.plugin.hotels.bukkit.HotelsMain
|
||||
name: Hotels
|
||||
version: ${project.version}
|
||||
author: M_Viper
|
||||
description: Allows the making of hotels and renting of rooms
|
||||
website: https://github.com/mviper/hotels
|
||||
load: POSTWORLD
|
||||
api-version: 1.21
|
||||
|
||||
depend: [Vault, WorldEdit, WorldGuard]
|
||||
|
||||
commands:
|
||||
Hotels:
|
||||
description: Hotels's main command
|
||||
aliases: [ht]
|
||||
usage: /hotels <subcommand> [args]
|
||||
permission: hotels.use
|
||||
|
||||
permissions:
|
||||
hotels.*:
|
||||
description: Gives access to all Hotels commands
|
||||
children:
|
||||
hotels.use: true
|
||||
hotels.admin: true
|
||||
hotels.create: true
|
||||
hotels.delete: true
|
||||
hotels.list: true
|
||||
hotels.rent: true
|
||||
hotels.manage: true
|
||||
|
||||
hotels.use:
|
||||
description: Allows using basic Hotels commands
|
||||
default: true
|
||||
|
||||
hotels.admin:
|
||||
description: Gives access to all admin commands
|
||||
default: op
|
||||
children:
|
||||
hotels.create: true
|
||||
hotels.delete: true
|
||||
hotels.manage: true
|
||||
hotels.bypass: true
|
||||
|
||||
hotels.create:
|
||||
description: Allows creating hotels
|
||||
default: op
|
||||
|
||||
hotels.delete:
|
||||
description: Allows deleting hotels
|
||||
default: op
|
||||
|
||||
hotels.list:
|
||||
description: Allows listing hotels
|
||||
default: true
|
||||
|
||||
hotels.rent:
|
||||
description: Allows renting rooms
|
||||
default: true
|
||||
|
||||
hotels.manage:
|
||||
description: Allows managing own hotels
|
||||
default: op
|
||||
|
||||
hotels.bypass:
|
||||
description: Bypasses all restrictions
|
||||
default: op
|
||||
Reference in New Issue
Block a user