Changes to make it an addon
WIP, loading of warps does not work for some reason.
This commit is contained in:
parent
d061ecc247
commit
9b1f8bd14c
|
@ -3,5 +3,3 @@ main: bskyblock.addin.warps.Warp
|
|||
version: 0.1
|
||||
|
||||
authors: [tastybento]
|
||||
|
||||
depend: [BSkyBlock]
|
|
@ -2,3 +2,6 @@
|
|||
# 0 or negative values will disable this restriction
|
||||
# 10 is default
|
||||
warplevelrestriction: 10
|
||||
|
||||
welcomeLine: [WELCOME]
|
||||
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package bskyblock.addin.warps;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* Makes code look nicer
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
public abstract class AddonHelper {
|
||||
protected final Warp plugin;
|
||||
protected final BSkyBlock bSkyBlock;
|
||||
|
||||
public AddonHelper(Warp plugin) {
|
||||
this.plugin = plugin;
|
||||
this.bSkyBlock = BSkyBlock.getPlugin();
|
||||
}
|
||||
|
||||
public final Logger getLogger() {
|
||||
return plugin.getLogger();
|
||||
}
|
||||
|
||||
public final void sendMessage(CommandSender sender, String message) {
|
||||
Util.sendMessage(sender, message);
|
||||
}
|
||||
|
||||
public final BSBLocale getLocale(CommandSender sender) {
|
||||
return plugin.getLocale(sender);
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of ASkyBlock.
|
||||
*
|
||||
* ASkyBlock is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ASkyBlock is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ASkyBlock. If not, see <http://www.gnu.org/licenses/>.
|
||||
*******************************************************************************/
|
||||
package bskyblock.addin.warps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
* This class is for a control panel button that has an icon, a command
|
||||
* to run if pressed or a link to
|
||||
* another control panel.
|
||||
*/
|
||||
public class CPItem {
|
||||
|
||||
private ItemStack item;
|
||||
private String command;
|
||||
private String nextSection;
|
||||
|
||||
|
||||
/**
|
||||
* A Control Panel item
|
||||
* @param material
|
||||
* @param name
|
||||
* @param command
|
||||
* @param nextSection
|
||||
*/
|
||||
public CPItem(Material material, String name, String command, String nextSection) {
|
||||
this.command = command;
|
||||
this.nextSection = nextSection;
|
||||
item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
// Handle multi line names (split by |)
|
||||
List<String> desc = new ArrayList<String>(Arrays.asList(name.split("\\|")));
|
||||
meta.setDisplayName(ChatColor.WHITE + desc.get(0));
|
||||
if (desc.size() > 1) {
|
||||
desc.remove(0); // Remove the name
|
||||
meta.setLore(desc);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public CPItem(ItemStack itemStack, String name, String command, String nextSection) {
|
||||
this.command = command;
|
||||
this.nextSection = nextSection;
|
||||
this.item = itemStack;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
// Handle multi line names (split by |)
|
||||
List<String> desc = new ArrayList<String>(Arrays.asList(name.split("\\|")));
|
||||
meta.setDisplayName(ChatColor.WHITE + desc.get(0));
|
||||
if (desc.size() > 1) {
|
||||
desc.remove(0); // Remove the name
|
||||
meta.setLore(desc);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
// For warps
|
||||
public CPItem(ItemStack itemStack, String command) {
|
||||
this.command = command;
|
||||
this.nextSection = "";
|
||||
this.item = itemStack;
|
||||
}
|
||||
|
||||
public void setLore(List<String> lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the command
|
||||
*/
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nextSection
|
||||
*/
|
||||
public String getNextSection() {
|
||||
return nextSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nextSection
|
||||
* the nextSection to set
|
||||
*/
|
||||
public void setNextSection(String nextSection) {
|
||||
this.nextSection = nextSection;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +1,51 @@
|
|||
package bskyblock.addin.warps;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import bskyblock.addin.warps.commands.Commands;
|
||||
import bskyblock.addin.warps.config.LocaleManager;
|
||||
import bskyblock.addin.warps.commands.WarpCommand;
|
||||
import bskyblock.addin.warps.commands.WarpsCommand;
|
||||
import bskyblock.addin.warps.config.PluginConfig;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
import us.tastybento.bskyblock.api.addons.Addon;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
* Addin to BSkyBlock that enables welcome warp signs
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Warp extends JavaPlugin {
|
||||
public class Warp extends Addon {
|
||||
|
||||
// The BSkyBlock plugin instance.
|
||||
private BSkyBlock bSkyBlock;
|
||||
|
||||
// Locale manager for this plugin
|
||||
private LocaleManager localeManager;
|
||||
|
||||
// Warp panel object
|
||||
private WarpPanel warpPanel;
|
||||
private WarpPanelManager warpPanelManager;
|
||||
|
||||
// Warps signs object
|
||||
private WarpSigns warpSigns;
|
||||
private WarpSignsManager warpSignsManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Load the plugin's config
|
||||
new PluginConfig(this);
|
||||
// Get the BSkyBlock plugin. This will be available because this plugin depends on it in plugin.yml.
|
||||
bSkyBlock = BSkyBlock.getPlugin();
|
||||
bSkyBlock = BSkyBlock.getInstance();
|
||||
// Check if it is enabled - it might be loaded, but not enabled.
|
||||
if (!bSkyBlock.isEnabled()) {
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
// Local locales
|
||||
localeManager = new LocaleManager(this);
|
||||
// We have to wait for the worlds to load, so we do the rest 1 tick later
|
||||
getServer().getScheduler().runTask(this, () -> {
|
||||
getServer().getScheduler().runTask(this.getBSkyBlock(), () -> {
|
||||
// Start warp signs
|
||||
warpSigns = new WarpSigns(this, bSkyBlock);
|
||||
getServer().getPluginManager().registerEvents(warpSigns, this);
|
||||
// Start the warp panel and register it for clicks
|
||||
warpPanel = new WarpPanel(this);
|
||||
getServer().getPluginManager().registerEvents(warpPanel, this);
|
||||
warpSignsManager = new WarpSignsManager(this, bSkyBlock);
|
||||
warpPanelManager = new WarpPanelManager(this);
|
||||
// Load the listener
|
||||
getServer().getPluginManager().registerEvents(warpSignsManager, bSkyBlock);
|
||||
// Register commands
|
||||
new Commands(this);
|
||||
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
|
||||
new WarpCommand(this, bsbIslandCmd);
|
||||
new WarpsCommand(this, bsbIslandCmd);
|
||||
});
|
||||
// Done
|
||||
}
|
||||
|
@ -60,41 +53,20 @@ public class Warp extends JavaPlugin {
|
|||
@Override
|
||||
public void onDisable(){
|
||||
// Save the warps
|
||||
if (warpSigns != null)
|
||||
warpSigns.saveWarpList();
|
||||
if (warpSignsManager != null)
|
||||
warpSignsManager.saveWarpList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale for this player
|
||||
* @param sender
|
||||
* @return Locale object for sender
|
||||
* Get warp panel manager
|
||||
* @return
|
||||
*/
|
||||
public BSBLocale getLocale(CommandSender sender) {
|
||||
return localeManager.getLocale(sender);
|
||||
public WarpPanelManager getWarpPanelManager() {
|
||||
return warpPanelManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale for this UUID
|
||||
* @param uuid
|
||||
* @return Locale object for UUID
|
||||
*/
|
||||
public BSBLocale getLocale(UUID uuid) {
|
||||
return localeManager.getLocale(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default locale object
|
||||
*/
|
||||
public BSBLocale getLocale() {
|
||||
return localeManager.getLocale();
|
||||
}
|
||||
|
||||
public WarpPanel getWarpPanel() {
|
||||
return warpPanel;
|
||||
}
|
||||
|
||||
public WarpSigns getWarpSigns() {
|
||||
return warpSigns;
|
||||
|
||||
public WarpSignsManager getWarpSignsManager() {
|
||||
return warpSignsManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,300 +0,0 @@
|
|||
package bskyblock.addin.warps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
public class WarpPanel extends AddonHelper implements Listener {
|
||||
private static final int PANELSIZE = 45; // Must be a multiple of 9
|
||||
private final static boolean DEBUG = false;
|
||||
private List<Inventory> warpPanel;
|
||||
private HashMap<UUID, ItemStack> cachedWarps;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
*/
|
||||
public WarpPanel(Warp plugin) {
|
||||
super(plugin);
|
||||
warpPanel = new ArrayList<Inventory>();
|
||||
cachedWarps = new HashMap<UUID,ItemStack>();
|
||||
//plugin.getLogger().info("DEBUG: loading the warp panel of size " + plugin.getWarpSigns().listSortedWarps().size());
|
||||
// Load the cache
|
||||
for (UUID playerUUID : plugin.getWarpSigns().listSortedWarps()) {
|
||||
addWarp(playerUUID);
|
||||
}
|
||||
// Make the panels
|
||||
updatePanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new warp to the cache. Does NOT update the panels
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void addWarp(UUID playerUUID) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Adding warp");
|
||||
// Check cached warps
|
||||
if (cachedWarps.containsKey(playerUUID)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Found in cache");
|
||||
// Get the item
|
||||
ItemStack playerSkull = cachedWarps.get(playerUUID);
|
||||
playerSkull = updateText(playerSkull, playerUUID);
|
||||
return;
|
||||
}
|
||||
//plugin.getLogger().info("DEBUG: New skull");
|
||||
// Get the item
|
||||
ItemStack playerSkull = getSkull(playerUUID);
|
||||
if (playerSkull == null) {
|
||||
// Nothing found and not available on the server
|
||||
return;
|
||||
}
|
||||
// Update the sign text
|
||||
playerSkull = updateText(playerSkull, playerUUID);
|
||||
cachedWarps.put(playerUUID, playerSkull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the skull for this player UUID
|
||||
* @param playerUUID
|
||||
* @return Player skull item
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private ItemStack getSkull(UUID playerUUID) {
|
||||
String playerName = bSkyBlock.getPlayers().getName(playerUUID);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: name of warp = " + playerName);
|
||||
ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
if (playerName == null) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().warning("Warp for Player: UUID " + playerUUID.toString() + " is unknown on this server, skipping...");
|
||||
return null;
|
||||
//playerName = playerUUID.toString().substring(0, 10);
|
||||
}
|
||||
SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
|
||||
meta.setOwner(playerName);
|
||||
meta.setDisplayName(ChatColor.WHITE + playerName);
|
||||
playerSkull.setItemMeta(meta);
|
||||
return playerSkull;
|
||||
}
|
||||
public Inventory getWarpPanel(int panelNumber) {
|
||||
//makePanel();
|
||||
if (panelNumber < 0) {
|
||||
panelNumber = 0;
|
||||
} else if (panelNumber > warpPanel.size()-1) {
|
||||
panelNumber = warpPanel.size()-1;
|
||||
}
|
||||
return warpPanel.get(panelNumber);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
Inventory inventory = event.getInventory(); // The inventory that was clicked in
|
||||
if (inventory.getName() == null) {
|
||||
return;
|
||||
}
|
||||
// The player that clicked the item
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
String title = inventory.getTitle();
|
||||
// The title must be the same for all locales because the warp panels are common
|
||||
if (!inventory.getTitle().startsWith(plugin.getLocale().get("warps.title") + " #")) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (event.getSlotType().equals(SlotType.OUTSIDE)) {
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
|
||||
player.closeInventory();
|
||||
player.updateInventory();
|
||||
return;
|
||||
}
|
||||
ItemStack clicked = event.getCurrentItem(); // The item that was clicked
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: clicked = " + clicked);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
|
||||
if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
int panelNumber = 0;
|
||||
try {
|
||||
panelNumber = Integer.valueOf(title.substring(title.indexOf('#')+ 1));
|
||||
} catch (Exception e) {
|
||||
panelNumber = 0;
|
||||
}
|
||||
if (clicked.getItemMeta().hasDisplayName()) {
|
||||
String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: command = " + command);
|
||||
if (command != null) {
|
||||
if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.getLocale().get("warps.next")))) {
|
||||
player.closeInventory();
|
||||
Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber+1));
|
||||
} else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.getLocale().get("warps.previous")))) {
|
||||
player.closeInventory();
|
||||
Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber-1));
|
||||
} else {
|
||||
player.closeInventory();
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("warps.warpToPlayersSign").replace("[player]", command));
|
||||
Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the text on all the warp icons.
|
||||
*/
|
||||
public void updateAllWarpText() {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: update all Warps");
|
||||
for (UUID playerUUID : cachedWarps.keySet()) {
|
||||
// Get the item
|
||||
ItemStack playerSkull = cachedWarps.get(playerUUID);
|
||||
playerSkull = updateText(playerSkull, playerUUID);
|
||||
}
|
||||
updatePanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the inventory panels from the warp list and adds nav buttons
|
||||
*/
|
||||
public void updatePanel() {
|
||||
// Clear the inventory panels
|
||||
warpPanel.clear();
|
||||
Collection<UUID> activeWarps = plugin.getWarpSigns().listSortedWarps();
|
||||
// Create the warp panels
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: warps size = " + activeWarps.size());
|
||||
int size = activeWarps.size();
|
||||
int panelNumber = size / (PANELSIZE-2);
|
||||
int remainder = (size % (PANELSIZE-2)) + 8 + 2;
|
||||
remainder -= (remainder % 9);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: panel number = " + panelNumber + " remainder = " + remainder);
|
||||
int i = 0;
|
||||
// TODO: Make panel title a string
|
||||
for (i = 0; i < panelNumber; i++) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: created panel " + (i+1));
|
||||
warpPanel.add(Bukkit.createInventory(null, PANELSIZE, plugin.getLocale().get("warps.title") + " #" + (i+1)));
|
||||
}
|
||||
// Make the last panel
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: created panel " + (i+1));
|
||||
warpPanel.add(Bukkit.createInventory(null, remainder, plugin.getLocale().get("warps.title") + " #" + (i+1)));
|
||||
panelNumber = 0;
|
||||
int slot = 0;
|
||||
// Run through all the warps and add them to the inventories with nav buttons
|
||||
for (UUID playerUUID: activeWarps) {
|
||||
ItemStack icon = cachedWarps.get(playerUUID);
|
||||
if (icon != null) {
|
||||
warpPanel.get(panelNumber).setItem(slot++, icon);
|
||||
|
||||
// Check if the panel is full
|
||||
if (slot == PANELSIZE-2) {
|
||||
// Add navigation buttons
|
||||
if (panelNumber > 0) {
|
||||
warpPanel.get(panelNumber).setItem(slot++, new CPItem(Material.SIGN,plugin.getLocale().get("warps.previous"),"warps " + (panelNumber-1),"").getItem());
|
||||
}
|
||||
warpPanel.get(panelNumber).setItem(slot, new CPItem(Material.SIGN,plugin.getLocale().get("warps.next"),"warps " + (panelNumber+1),"").getItem());
|
||||
// Move onto the next panel
|
||||
panelNumber++;
|
||||
slot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (remainder != 0 && panelNumber > 0) {
|
||||
warpPanel.get(panelNumber).setItem(slot++, new CPItem(Material.SIGN,plugin.getLocale().get("warps.previous"),"warps " + (panelNumber-1),"").getItem());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the meta text on the skull by looking at the warp sign
|
||||
* This MUST be run 1 TICK AFTER the sign has been created otherwise the sign is blank
|
||||
* @param playerSkull
|
||||
* @param playerUUID
|
||||
* @return updated skull item stack
|
||||
*/
|
||||
private ItemStack updateText(ItemStack playerSkull, final UUID playerUUID) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Updating text on item");
|
||||
ItemMeta meta = playerSkull.getItemMeta();
|
||||
//get the sign info
|
||||
Location signLocation = plugin.getWarpSigns().getWarp(playerUUID);
|
||||
if (signLocation == null) {
|
||||
plugin.getWarpSigns().removeWarp(playerUUID);
|
||||
return playerSkull;
|
||||
}
|
||||
//plugin.getLogger().info("DEBUG: block type = " + signLocation.getBlock().getType());
|
||||
// Get the sign info if it exists
|
||||
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||
Sign sign = (Sign)signLocation.getBlock().getState();
|
||||
List<String> lines = new ArrayList<String>(Arrays.asList(sign.getLines()));
|
||||
// Check for PVP and add warning
|
||||
Island island = bSkyBlock.getIslands().getIsland(playerUUID);
|
||||
if (island != null) {
|
||||
if ((signLocation.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||
|| (signLocation.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: pvp warning added");
|
||||
lines.add(ChatColor.RED + bSkyBlock.getLocale(playerUUID).get("igs." + SettingsFlag.PVP_OVERWORLD));
|
||||
}
|
||||
}
|
||||
meta.setLore(lines);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: lines = " + lines);
|
||||
}
|
||||
playerSkull.setItemMeta(meta);
|
||||
return playerSkull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only change the text of the warp
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void updateWarp(UUID playerUUID) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: update Warp");
|
||||
|
||||
if (cachedWarps.containsKey(playerUUID)) {
|
||||
// Get the item
|
||||
ItemStack playerSkull = cachedWarps.get(playerUUID);
|
||||
playerSkull = updateText(playerSkull, playerUUID);
|
||||
updatePanel();
|
||||
} else {
|
||||
plugin.getLogger().warning("Warps: update requested, but player unknown " + playerUUID.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
package bskyblock.addin.warps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.panels.ClickType;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem.ClickHandler;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
|
||||
public class WarpPanelManager {
|
||||
|
||||
private static final boolean DEBUG = true;
|
||||
private static final int PANEL_MAX_SIZE = 47;
|
||||
private Warp plugin;
|
||||
// This is a cache of heads, so they don't need to be created everytime
|
||||
private HashMap<UUID, PanelItem> cachedWarps;
|
||||
|
||||
|
||||
public WarpPanelManager(Warp plugin) {
|
||||
this.plugin = plugin;
|
||||
cachedWarps = new HashMap<>();
|
||||
createWarpCache();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method makes the cache of heads based on the warps available
|
||||
*/
|
||||
private void createWarpCache() {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: creating warp cache");
|
||||
cachedWarps.clear();
|
||||
for (UUID warpOwner : plugin.getWarpSignsManager().getSortedWarps()) {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: adding warp");
|
||||
cachedWarps.put(warpOwner, getPanelItem(warpOwner));
|
||||
}
|
||||
}
|
||||
|
||||
private PanelItem getPanelItem(UUID warpOwner) {
|
||||
return new PanelItemBuilder()
|
||||
.setName(plugin.getBSkyBlock().getPlayers().getName(warpOwner))
|
||||
.setDescription(plugin.getWarpSignsManager().getSignText(warpOwner))
|
||||
.setIcon(getSkull(warpOwner))
|
||||
.setClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onClick(User user, ClickType click) {
|
||||
plugin.getWarpSignsManager().warpPlayer(user, warpOwner);
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the skull for this player UUID
|
||||
* @param playerUUID
|
||||
* @return Player skull item
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private ItemStack getSkull(UUID playerUUID) {
|
||||
String playerName = plugin.getBSkyBlock().getPlayers().getName(playerUUID);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: name of warp = " + playerName);
|
||||
ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
if (playerName == null) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().warning("Warp for Player: UUID " + playerUUID.toString() + " is unknown on this server, skipping...");
|
||||
return null;
|
||||
}
|
||||
SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
|
||||
meta.setOwner(playerName);
|
||||
meta.setDisplayName(ChatColor.WHITE + playerName);
|
||||
playerSkull.setItemMeta(meta);
|
||||
return playerSkull;
|
||||
}
|
||||
|
||||
public void showWarpPanel(User user, int index) {
|
||||
List<UUID> warps = new ArrayList<>(plugin.getWarpSignsManager().getSortedWarps());
|
||||
if (DEBUG) {
|
||||
Bukkit.getLogger().info("DEBUG: showing warps. warps list is " + warps.size());
|
||||
}
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
|
||||
index = warps.size() / PANEL_MAX_SIZE;
|
||||
}
|
||||
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title"));
|
||||
int i = index * PANEL_MAX_SIZE;
|
||||
for (; i < (index * PANEL_MAX_SIZE + PANEL_MAX_SIZE) && i < warps.size(); i++) {
|
||||
UUID owner = warps.get(i);
|
||||
if (!cachedWarps.containsKey(owner)) {
|
||||
cachedWarps.put(owner, getPanelItem(owner));
|
||||
}
|
||||
panelBuilder.addItem(cachedWarps.get(owner));
|
||||
}
|
||||
final int panelNum = index;
|
||||
// Add signs
|
||||
if (i < warps.size()) {
|
||||
// Next
|
||||
panelBuilder.addItem(new PanelItemBuilder()
|
||||
.setName("Next")
|
||||
.setIcon(new ItemStack(Material.SIGN))
|
||||
.setClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onClick(User user, ClickType click) {
|
||||
showWarpPanel(user, panelNum+1);
|
||||
return true;
|
||||
}
|
||||
|
||||
}).build());
|
||||
}
|
||||
if (i > PANEL_MAX_SIZE) {
|
||||
// Previous
|
||||
panelBuilder.addItem(new PanelItemBuilder()
|
||||
.setName("Next")
|
||||
.setIcon(new ItemStack(Material.SIGN))
|
||||
.setClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onClick(User user, ClickType click) {
|
||||
showWarpPanel(user, panelNum-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
}).build());
|
||||
}
|
||||
panelBuilder.build();
|
||||
}
|
||||
}
|
|
@ -3,9 +3,12 @@ package bskyblock.addin.warps;
|
|||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -16,25 +19,28 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import bskyblock.addin.warps.database.object.Warps;
|
||||
import bskyblock.addin.warps.database.object.WarpsDO;
|
||||
import bskyblock.addin.warps.event.WarpInitiateEvent;
|
||||
import bskyblock.addin.warps.event.WarpListEvent;
|
||||
import bskyblock.addin.warps.event.WarpRemoveEvent;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
import us.tastybento.bskyblock.util.VaultHelper;
|
||||
|
||||
/**
|
||||
* Handles warping. Players can add one sign
|
||||
|
@ -42,220 +48,36 @@ import us.tastybento.bskyblock.util.VaultHelper;
|
|||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class WarpSigns extends AddonHelper implements Listener {
|
||||
//private final static boolean DEBUG = false;
|
||||
public class WarpSignsManager implements Listener {
|
||||
private static final boolean DEBUG = true;
|
||||
private BSkyBlock bSkyBlock;
|
||||
// Map of all warps stored as player, warp sign Location
|
||||
private Map<UUID, Location> warpList;
|
||||
// Database handler for level data
|
||||
private AbstractDatabaseHandler<Warps> handler;
|
||||
private AbstractDatabaseHandler<WarpsDO> handler;
|
||||
|
||||
// The BSkyBlock database object
|
||||
private BSBDatabase database;
|
||||
|
||||
private Warp plugin;
|
||||
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public WarpSigns(Warp plugin, BSkyBlock bSkyBlock) {
|
||||
super(plugin);
|
||||
public WarpSignsManager(Warp plugin, BSkyBlock bSkyBlock) {
|
||||
this.plugin = plugin;
|
||||
this.bSkyBlock = bSkyBlock;
|
||||
// Get the BSkyBlock database
|
||||
database = BSBDatabase.getDatabase();
|
||||
// Set up the database handler to store and retrieve Island classes
|
||||
// Note that these are saved by the BSkyBlock database
|
||||
handler = (AbstractDatabaseHandler<Warps>) database.getHandler(bSkyBlock, Warps.class);
|
||||
handler = (AbstractDatabaseHandler<WarpsDO>) database.getHandler(bSkyBlock, WarpsDO.class);
|
||||
// Load the warps
|
||||
loadWarpList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a sign has been broken
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
||||
public void onSignBreak(BlockBreakEvent e) {
|
||||
Block b = e.getBlock();
|
||||
Player player = e.getPlayer();
|
||||
if (b.getWorld().equals(IslandWorld.getIslandWorld()) || b.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign s = (Sign) b.getState();
|
||||
if (s != null) {
|
||||
//plugin.getLogger().info("DEBUG: sign found at location " + s.toString());
|
||||
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getLocale().get("warps.welcomeLine"))) {
|
||||
// Do a quick check to see if this sign location is in
|
||||
//plugin.getLogger().info("DEBUG: welcome sign");
|
||||
// the list of warp signs
|
||||
if (warpList.containsValue(s.getLocation())) {
|
||||
//plugin.getLogger().info("DEBUG: warp sign is in list");
|
||||
// Welcome sign detected - check to see if it is
|
||||
// this player's sign
|
||||
if ((warpList.containsKey(player.getUniqueId()) && warpList.get(player.getUniqueId()).equals(s.getLocation()))) {
|
||||
// Player removed sign
|
||||
removeWarp(s.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
|
||||
} else if (player.isOp() || player.hasPermission(us.tastybento.bskyblock.config.Settings.PERMPREFIX + "mod.removesign")) {
|
||||
// Op or mod removed sign
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("warps.removed"));
|
||||
removeWarp(s.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
|
||||
} else {
|
||||
// Someone else's sign - not allowed
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.no-remove"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for Sign Changes
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
||||
public void onSignWarpCreate(SignChangeEvent e) {
|
||||
//plugin.getLogger().info("DEBUG: SignChangeEvent called");
|
||||
String title = e.getLine(0);
|
||||
Player player = e.getPlayer();
|
||||
if (player.getWorld().equals(IslandWorld.getIslandWorld()) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
//plugin.getLogger().info("DEBUG: Correct world");
|
||||
if (e.getBlock().getType().equals(Material.SIGN_POST) || e.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||
|
||||
//plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
|
||||
// Check if someone is changing their own sign
|
||||
// This should never happen !!
|
||||
if (title.equalsIgnoreCase(plugin.getLocale().get("warps.welcomeLine"))) {
|
||||
//plugin.getLogger().info("DEBUG: Welcome sign detected");
|
||||
// Welcome sign detected - check permissions
|
||||
if (!(VaultHelper.hasPerm(player, us.tastybento.bskyblock.config.Settings.PERMPREFIX + "island.addwarp"))) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.no-permission"));
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if(!(ASkyBlockAPI.getInstance().getLongIslandLevel(player.getUniqueId()) > Settings.warpLevelsRestriction)){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.NotEnoughLevel"));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// Check that the player is on their island
|
||||
if (!(bSkyBlock.getIslands().playerIsOnIsland(player))) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.not-on-island"));
|
||||
e.setLine(0, ChatColor.RED + plugin.getLocale().get("warps.welcomeLine"));
|
||||
return;
|
||||
}
|
||||
// Check if the player already has a sign
|
||||
final Location oldSignLoc = getWarp(player.getUniqueId());
|
||||
if (oldSignLoc == null) {
|
||||
//plugin.getLogger().info("DEBUG: Player does not have a sign already");
|
||||
// First time the sign has been placed or this is a new
|
||||
// sign
|
||||
if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("warps.success"));
|
||||
e.setLine(0, ChatColor.GREEN + plugin.getLocale().get("warps.welcomeLine"));
|
||||
for (int i = 1; i<4; i++) {
|
||||
e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
|
||||
}
|
||||
} else {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.duplicate"));
|
||||
e.setLine(0, ChatColor.RED + plugin.getLocale().get("warps.welcomeLine"));
|
||||
for (int i = 1; i<4; i++) {
|
||||
e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//plugin.getLogger().info("DEBUG: Player already has a Sign");
|
||||
// A sign already exists. Check if it still there and if
|
||||
// so,
|
||||
// deactivate it
|
||||
Block oldSignBlock = oldSignLoc.getBlock();
|
||||
if (oldSignBlock.getType().equals(Material.SIGN_POST) || oldSignBlock.getType().equals(Material.WALL_SIGN)) {
|
||||
// The block is still a sign
|
||||
//plugin.getLogger().info("DEBUG: The block is still a sign");
|
||||
Sign oldSign = (Sign) oldSignBlock.getState();
|
||||
if (oldSign != null) {
|
||||
//plugin.getLogger().info("DEBUG: Sign block is a sign");
|
||||
if (oldSign.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getLocale().get("warps.welcomeLine"))) {
|
||||
//plugin.getLogger().info("DEBUG: Old sign had a green welcome");
|
||||
oldSign.setLine(0, ChatColor.RED + plugin.getLocale().get("warps.welcomeLine"));
|
||||
oldSign.update(true, false);
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.deactivate"));
|
||||
removeWarp(player.getUniqueId());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, oldSign.getLocation(), player.getUniqueId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set up the warp
|
||||
if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("warps.error.success"));
|
||||
e.setLine(0, ChatColor.GREEN + plugin.getLocale().get("warps.welcomeLine"));
|
||||
} else {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.duplicate"));
|
||||
e.setLine(0, ChatColor.RED + plugin.getLocale().get("warps.welcomeLine"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the warp lists to the database
|
||||
*/
|
||||
public void saveWarpList() {
|
||||
if (warpList == null) {
|
||||
return;
|
||||
}
|
||||
//plugin.getLogger().info("Saving warps...");
|
||||
try {
|
||||
handler.saveObject(new Warps().save(warpList));
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
|
||||
| InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the warps and checks if they still exist
|
||||
*/
|
||||
public void loadWarpList() {
|
||||
plugin.getLogger().info("Loading warps...");
|
||||
warpList = new HashMap<>();
|
||||
try {
|
||||
Warps warps = handler.loadObject("warps");
|
||||
// If there's nothing there, start fresh
|
||||
if (warps == null) {
|
||||
warpList = new HashMap<>();
|
||||
} else {
|
||||
warpList = warps.getWarpSigns();
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*
|
||||
for (Entry<UUID, Location> en : warpList.entrySet()) {
|
||||
plugin.getLogger().info("DEBUG: " + en.getKey() + " " + en.getValue());
|
||||
}*/
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Chck the warp sign
|
||||
Block b = en.getValue().getBlock();
|
||||
// Check that a warp sign is still there
|
||||
if (!b.getType().equals(Material.SIGN_POST) && !b.getType().equals(Material.WALL_SIGN)) {
|
||||
plugin.getLogger().warning("Warp at location " + en.getValue() + " has no sign - removing.");
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores warps in the warp array
|
||||
*
|
||||
|
@ -276,139 +98,10 @@ public class WarpSigns extends AddonHelper implements Listener {
|
|||
}
|
||||
warpList.put(playerUUID, loc);
|
||||
saveWarpList();
|
||||
// Update warp signs
|
||||
// Run one tick later because text gets updated at the end of tick
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getWarpPanel().addWarp(playerUUID);
|
||||
plugin.getWarpPanel().updatePanel();
|
||||
Bukkit.getPluginManager().callEvent(new WarpInitiateEvent(plugin, loc, playerUUID));
|
||||
}});
|
||||
Bukkit.getPluginManager().callEvent(new WarpInitiateEvent(plugin, loc, playerUUID));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a warp when the welcome sign is destroyed. Called by
|
||||
* WarpSigns.java.
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
public void removeWarp(UUID uuid) {
|
||||
if (warpList.containsKey(uuid)) {
|
||||
popSign(warpList.get(uuid));
|
||||
warpList.remove(uuid);
|
||||
}
|
||||
saveWarpList();
|
||||
// Update warp signs
|
||||
// Run one tick later because text gets updated at the end of tick
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getWarpPanel().updatePanel();
|
||||
|
||||
}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the sign to red if it exists
|
||||
* @param loc
|
||||
*/
|
||||
private void popSign(Location loc) {
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign s = (Sign) b.getState();
|
||||
if (s != null) {
|
||||
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getLocale().get("warps.welcomeLine"))) {
|
||||
s.setLine(0, ChatColor.RED + plugin.getLocale().get("warps.welcomeLine"));
|
||||
s.update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a warp at a location.
|
||||
*
|
||||
* @param loc
|
||||
*/
|
||||
public void removeWarp(Location loc) {
|
||||
//plugin.getLogger().info("Asked to remove warp at " + loc);
|
||||
popSign(loc);
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
if (en.getValue().equals(loc)) {
|
||||
// Inform player
|
||||
Player p = plugin.getServer().getPlayer(en.getKey());
|
||||
if (p != null) {
|
||||
// Inform the player
|
||||
Util.sendMessage(p, ChatColor.RED + plugin.getLocale(p.getUniqueId()).get("warps.sign-removed"));
|
||||
}
|
||||
/*
|
||||
else {
|
||||
plugin.getMessages().setMessage(en.getKey(), ChatColor.RED + plugin.myLocale(en.getKey()).warpssignRemoved);
|
||||
}
|
||||
*/
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
saveWarpList();
|
||||
plugin.getWarpPanel().updatePanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the known warps
|
||||
*
|
||||
* @return String set of warps
|
||||
*/
|
||||
public Set<UUID> listWarps() {
|
||||
// Check if any of the warp locations are null
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Check if the location of the warp still exists, if not, delete it
|
||||
if (en.getValue() == null) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return warpList.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Sorted list of warps with most recent players listed first
|
||||
*/
|
||||
public Collection<UUID> listSortedWarps() {
|
||||
// Bigger value of time means a more recent login
|
||||
TreeMap<Long, UUID> map = new TreeMap<Long, UUID>();
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Check if the location of the warp still exists, if not, delete it
|
||||
if (en.getValue() == null) {
|
||||
it.remove();
|
||||
} else {
|
||||
UUID uuid = en.getKey();
|
||||
// If never played, will be zero
|
||||
long lastPlayed = plugin.getServer().getOfflinePlayer(uuid).getLastPlayed();
|
||||
// This aims to avoid the chance that players logged off at exactly the same time
|
||||
if (!map.isEmpty() && map.containsKey(lastPlayed)) {
|
||||
lastPlayed = map.firstKey() - 1;
|
||||
}
|
||||
map.put(lastPlayed, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<UUID> result = map.descendingMap().values();
|
||||
// Fire event
|
||||
WarpListEvent event = new WarpListEvent(plugin, result);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
// Get the result of any changes by listeners
|
||||
result = event.getWarps();
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Provides the location of the warp for player or null if one is not found
|
||||
*
|
||||
|
@ -441,5 +134,457 @@ public class WarpSigns extends AddonHelper implements Listener {
|
|||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted list of warps with most recent players listed first
|
||||
* @return UUID collenction
|
||||
*/
|
||||
public Collection<UUID> getSortedWarps() {
|
||||
// Bigger value of time means a more recent login
|
||||
TreeMap<Long, UUID> map = new TreeMap<Long, UUID>();
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Check if the location of the warp still exists, if not, delete it
|
||||
if (en.getValue() == null) {
|
||||
it.remove();
|
||||
} else {
|
||||
UUID uuid = en.getKey();
|
||||
// If never played, will be zero
|
||||
long lastPlayed = plugin.getServer().getOfflinePlayer(uuid).getLastPlayed();
|
||||
// This aims to avoid the chance that players logged off at exactly the same time
|
||||
if (!map.isEmpty() && map.containsKey(lastPlayed)) {
|
||||
lastPlayed = map.firstKey() - 1;
|
||||
}
|
||||
map.put(lastPlayed, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<UUID> result = map.descendingMap().values();
|
||||
// Fire event
|
||||
WarpListEvent event = new WarpListEvent(plugin, result);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
// Get the result of any changes by listeners
|
||||
result = event.getWarps();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the known warps
|
||||
*
|
||||
* @return UUID set of warps
|
||||
*/
|
||||
public Set<UUID> listWarps() {
|
||||
// Check if any of the warp locations are null
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Check if the location of the warp still exists, if not, delete it
|
||||
if (en.getValue() == null) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return warpList.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the warps and checks if they still exist
|
||||
*/
|
||||
public void loadWarpList() {
|
||||
plugin.getLogger().info("Loading warps...");
|
||||
warpList = new HashMap<>();
|
||||
try {
|
||||
WarpsDO warps = handler.loadObject("warps");
|
||||
// If there's nothing there, start fresh
|
||||
if (warps == null) {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: nothing in the database");
|
||||
warpList = new HashMap<>();
|
||||
} else {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: something in the database");
|
||||
warpList = warps.getWarpSigns();
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: warpList size = " + warpList.size());
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
// Check the warp sign
|
||||
Block b = en.getValue().getBlock();
|
||||
// Check that a warp sign is still there
|
||||
if (!b.getType().equals(Material.SIGN_POST) && !b.getType().equals(Material.WALL_SIGN)) {
|
||||
plugin.getLogger().warning("Warp at location " + en.getValue() + " has no sign - removing.");
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a sign has been broken
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
||||
public void onSignBreak(BlockBreakEvent e) {
|
||||
Block b = e.getBlock();
|
||||
User player = User.getInstance(e.getPlayer());
|
||||
if (b.getWorld().equals(IslandWorld.getIslandWorld()) || b.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign s = (Sign) b.getState();
|
||||
if (s != null) {
|
||||
//plugin.getLogger().info("DEBUG: sign found at location " + s.toString());
|
||||
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"))) {
|
||||
// Do a quick check to see if this sign location is in
|
||||
//plugin.getLogger().info("DEBUG: welcome sign");
|
||||
// the list of warp signs
|
||||
if (warpList.containsValue(s.getLocation())) {
|
||||
//plugin.getLogger().info("DEBUG: warp sign is in list");
|
||||
// Welcome sign detected - check to see if it is
|
||||
// this player's sign
|
||||
if ((warpList.containsKey(player.getUniqueId()) && warpList.get(player.getUniqueId()).equals(s.getLocation()))) {
|
||||
// Player removed sign
|
||||
removeWarp(s.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
|
||||
} else if (player.isOp() || player.hasPermission(us.tastybento.bskyblock.config.Settings.PERMPREFIX + "mod.removesign")) {
|
||||
// Op or mod removed sign
|
||||
player.sendMessage("warps.removed");
|
||||
removeWarp(s.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId()));
|
||||
} else {
|
||||
// Someone else's sign - not allowed
|
||||
player.sendMessage("warps.error.no-remove");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for Sign Changes
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
||||
public void onSignWarpCreate(SignChangeEvent e) {
|
||||
plugin.getLogger().info("DEBUG: SignChangeEvent called");
|
||||
String title = e.getLine(0);
|
||||
User player = User.getInstance(e.getPlayer());
|
||||
if (player.getWorld().equals(IslandWorld.getIslandWorld()) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||
plugin.getLogger().info("DEBUG: Correct world");
|
||||
if (e.getBlock().getType().equals(Material.SIGN_POST) || e.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||
|
||||
plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
|
||||
// Check if someone is changing their own sign
|
||||
// This should never happen !!
|
||||
if (title.equalsIgnoreCase(plugin.getConfig().getString("welcomeLine"))) {
|
||||
plugin.getLogger().info("DEBUG: Welcome sign detected");
|
||||
// Welcome sign detected - check permissions
|
||||
if (!(player.hasPermission(us.tastybento.bskyblock.config.Settings.PERMPREFIX + "island.addwarp"))) {
|
||||
player.sendMessage("warps.error.no-permission");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if(!(ASkyBlockAPI.getInstance().getLongIslandLevel(player.getUniqueId()) > Settings.warpLevelsRestriction)){
|
||||
player.sendMessage(ChatColor.RED + "warps.error.NotEnoughLevel"));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// Check that the player is on their island
|
||||
if (!(bSkyBlock.getIslands().playerIsOnIsland(player))) {
|
||||
player.sendMessage("warps.error.not-on-island");
|
||||
e.setLine(0, ChatColor.RED + plugin.getConfig().getString("welcomeLine"));
|
||||
return;
|
||||
}
|
||||
// Check if the player already has a sign
|
||||
final Location oldSignLoc = getWarp(player.getUniqueId());
|
||||
if (oldSignLoc == null) {
|
||||
//plugin.getLogger().info("DEBUG: Player does not have a sign already");
|
||||
// First time the sign has been placed or this is a new
|
||||
// sign
|
||||
if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
|
||||
player.sendMessage("warps.success");
|
||||
e.setLine(0, ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"));
|
||||
for (int i = 1; i<4; i++) {
|
||||
e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("warps.error.duplicate");
|
||||
e.setLine(0, ChatColor.RED + plugin.getConfig().getString("welcomeLine"));
|
||||
for (int i = 1; i<4; i++) {
|
||||
e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//plugin.getLogger().info("DEBUG: Player already has a Sign");
|
||||
// A sign already exists. Check if it still there and if
|
||||
// so,
|
||||
// deactivate it
|
||||
Block oldSignBlock = oldSignLoc.getBlock();
|
||||
if (oldSignBlock.getType().equals(Material.SIGN_POST) || oldSignBlock.getType().equals(Material.WALL_SIGN)) {
|
||||
// The block is still a sign
|
||||
//plugin.getLogger().info("DEBUG: The block is still a sign");
|
||||
Sign oldSign = (Sign) oldSignBlock.getState();
|
||||
if (oldSign != null) {
|
||||
//plugin.getLogger().info("DEBUG: Sign block is a sign");
|
||||
if (oldSign.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"))) {
|
||||
//plugin.getLogger().info("DEBUG: Old sign had a green welcome");
|
||||
oldSign.setLine(0, ChatColor.RED + plugin.getConfig().getString("welcomeLine"));
|
||||
oldSign.update(true, false);
|
||||
player.sendMessage("warps.deactivate");
|
||||
removeWarp(player.getUniqueId());
|
||||
Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, oldSign.getLocation(), player.getUniqueId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set up the warp
|
||||
if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
|
||||
player.sendMessage("warps.error.success");
|
||||
e.setLine(0, ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"));
|
||||
} else {
|
||||
player.sendMessage("warps.error.duplicate");
|
||||
e.setLine(0, ChatColor.RED + plugin.getConfig().getString("welcomeLine"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the sign to red if it exists
|
||||
* @param loc
|
||||
*/
|
||||
private void popSign(Location loc) {
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign s = (Sign) b.getState();
|
||||
if (s != null) {
|
||||
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"))) {
|
||||
s.setLine(0, ChatColor.RED + plugin.getConfig().getString("welcomeLine"));
|
||||
s.update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a warp at a location.
|
||||
*
|
||||
* @param loc
|
||||
*/
|
||||
public void removeWarp(Location loc) {
|
||||
//plugin.getLogger().info("Asked to remove warp at " + loc);
|
||||
popSign(loc);
|
||||
Iterator<Entry<UUID, Location>> it = warpList.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
if (en.getValue().equals(loc)) {
|
||||
// Inform player
|
||||
User p = User.getInstance(plugin.getServer().getPlayer(en.getKey()));
|
||||
if (p != null) {
|
||||
// Inform the player
|
||||
p.sendMessage("warps.sign-removed");
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
saveWarpList();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Removes a warp when the welcome sign is destroyed. Called by
|
||||
* WarpSigns.java.
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
public void removeWarp(UUID uuid) {
|
||||
if (warpList.containsKey(uuid)) {
|
||||
popSign(warpList.get(uuid));
|
||||
warpList.remove(uuid);
|
||||
}
|
||||
saveWarpList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the warp lists to the database
|
||||
*/
|
||||
public void saveWarpList() {
|
||||
if (warpList == null) {
|
||||
return;
|
||||
}
|
||||
//plugin.getLogger().info("Saving warps...");
|
||||
try {
|
||||
handler.saveObject(new WarpsDO().save(warpList));
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
|
||||
| InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the warp sign text
|
||||
* @param uuid
|
||||
* @return List of lines
|
||||
*/
|
||||
public List<String> getSignText(UUID uuid) {
|
||||
List<String> result = new ArrayList<>();
|
||||
//get the sign info
|
||||
Location signLocation = getWarp(uuid);
|
||||
if (signLocation == null) {
|
||||
plugin.getWarpSignsManager().removeWarp(uuid);
|
||||
} else
|
||||
// Get the sign info if it exists
|
||||
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||
Sign sign = (Sign)signLocation.getBlock().getState();
|
||||
result.addAll(Arrays.asList(sign.getLines()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warps a player to a spot in front of a sign
|
||||
* @param user
|
||||
* @param inFront
|
||||
* @param foundWarp
|
||||
* @param directionFacing
|
||||
*/
|
||||
private void warpPlayer(User user, Location inFront, UUID foundWarp, BlockFace directionFacing, boolean pvp) {
|
||||
// convert blockface to angle
|
||||
float yaw = blockFaceToFloat(directionFacing);
|
||||
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
|
||||
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
||||
user.teleport(actualWarp);
|
||||
if (pvp) {
|
||||
user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.allowed"));
|
||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||
} else {
|
||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||
}
|
||||
User warpOwner = User.getInstance(foundWarp);
|
||||
if (!warpOwner.equals(user)) {
|
||||
warpOwner.sendMessage("warps.PlayerWarped", "[name]", user.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts block face direction to radial degrees. Returns 0 if block face
|
||||
* is not radial.
|
||||
*
|
||||
* @param face
|
||||
* @return degrees
|
||||
*/
|
||||
private float blockFaceToFloat(BlockFace face) {
|
||||
switch (face) {
|
||||
case EAST:
|
||||
return 90F;
|
||||
case EAST_NORTH_EAST:
|
||||
return 67.5F;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 0F;
|
||||
case NORTH:
|
||||
return 0F;
|
||||
case NORTH_EAST:
|
||||
return 45F;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 22.5F;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 337.5F;
|
||||
case NORTH_WEST:
|
||||
return 315F;
|
||||
case SOUTH:
|
||||
return 180F;
|
||||
case SOUTH_EAST:
|
||||
return 135F;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 157.5F;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 202.5F;
|
||||
case SOUTH_WEST:
|
||||
return 225F;
|
||||
case WEST:
|
||||
return 270F;
|
||||
case WEST_NORTH_WEST:
|
||||
return 292.5F;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 247.5F;
|
||||
default:
|
||||
return 0F;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Warps a user to the warp owner by owner
|
||||
* @param user
|
||||
* @param owner
|
||||
*/
|
||||
public void warpPlayer(User user, UUID owner) {
|
||||
final Location warpSpot = plugin.getWarpSignsManager().getWarp(owner);
|
||||
// Check if the warp spot is safe
|
||||
if (warpSpot == null) {
|
||||
user.sendMessage("warps.error.NotReadyYet");
|
||||
plugin.getLogger().warning("Null warp found, owned by " + plugin.getBSkyBlock().getPlayers().getName(owner));
|
||||
return;
|
||||
}
|
||||
// Find out if island is locked
|
||||
// TODO: Fire event
|
||||
|
||||
Island island = plugin.getBSkyBlock().getIslands().getIsland(owner);
|
||||
boolean pvp = false;
|
||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||
pvp = true;
|
||||
}
|
||||
// Find out which direction the warp is facing
|
||||
Block b = warpSpot.getBlock();
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
|
||||
BlockFace directionFacing = s.getFacing();
|
||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||
Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
|
||||
if ((Util.isSafeLocation(inFront))) {
|
||||
plugin.getWarpSignsManager().warpPlayer(user, inFront, owner, directionFacing, pvp);
|
||||
return;
|
||||
} else if (b.getType().equals(Material.WALL_SIGN) && Util.isSafeLocation(oneDown)) {
|
||||
// Try one block down if this is a wall sign
|
||||
plugin.getWarpSignsManager().warpPlayer(user, oneDown, owner, directionFacing, pvp);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Warp has been removed
|
||||
user.sendMessage("warps.error.DoesNotExist");
|
||||
plugin.getWarpSignsManager().removeWarp(warpSpot);
|
||||
return;
|
||||
}
|
||||
if (!(Util.isSafeLocation(warpSpot))) {
|
||||
user.sendMessage("warps.error.NotSafe");
|
||||
// WALL_SIGN's will always be unsafe if the place in front is obscured.
|
||||
if (b.getType().equals(Material.SIGN_POST)) {
|
||||
plugin.getLogger().warning(
|
||||
"Unsafe warp found at " + warpSpot.toString() + " owned by " + plugin.getBSkyBlock().getPlayers().getName(owner));
|
||||
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(),
|
||||
warpSpot.getBlockZ() + 0.5D);
|
||||
user.teleport(actualWarp);
|
||||
if (pvp) {
|
||||
user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.Allowed"));
|
||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||
} else {
|
||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,270 +0,0 @@
|
|||
package bskyblock.addin.warps.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bskyblock.addin.warps.AddonHelper;
|
||||
import bskyblock.addin.warps.Warp;
|
||||
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
||||
import us.tastybento.bskyblock.api.commands.CanUseResp;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
import us.tastybento.bskyblock.util.VaultHelper;
|
||||
|
||||
public class Commands extends AddonHelper {
|
||||
|
||||
public Commands(Warp plugin) {
|
||||
super(plugin);
|
||||
setupCommands();
|
||||
}
|
||||
|
||||
private void setupCommands() {
|
||||
// island warp command
|
||||
bSkyBlock.addSubCommand(new ArgumentHandler("island") {
|
||||
|
||||
@Override
|
||||
public CanUseResp canUse(CommandSender sender) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new CanUseResp(false);
|
||||
}
|
||||
if (VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "island.warp")) {
|
||||
return new CanUseResp(true);
|
||||
}
|
||||
return new CanUseResp(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 1) {
|
||||
// Warp somewhere command
|
||||
Player player = (Player)sender;
|
||||
final Set<UUID> warpList = plugin.getWarpSigns().listWarps();
|
||||
if (warpList.isEmpty()) {
|
||||
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(player.getUniqueId()).get("warps.errorNoWarpsYet"));
|
||||
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.addwarp")) {
|
||||
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale().get("warps.warpTip"));
|
||||
} else {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("error.NoPermission"));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// Check if this is part of a name
|
||||
UUID foundWarp = null;
|
||||
for (UUID warp : warpList) {
|
||||
if (warp == null)
|
||||
continue;
|
||||
if (bSkyBlock.getPlayers().getName(warp).toLowerCase().equals(args[0].toLowerCase())) {
|
||||
foundWarp = warp;
|
||||
break;
|
||||
} else if (bSkyBlock.getPlayers().getName(warp).toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
foundWarp = warp;
|
||||
}
|
||||
}
|
||||
if (foundWarp == null) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.DoesNotExist"));
|
||||
return;
|
||||
} else {
|
||||
// Warp exists!
|
||||
final Location warpSpot = plugin.getWarpSigns().getWarp(foundWarp);
|
||||
// Check if the warp spot is safe
|
||||
if (warpSpot == null) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.NotReadyYet"));
|
||||
plugin.getLogger().warning("Null warp found, owned by " + bSkyBlock.getPlayers().getName(foundWarp));
|
||||
return;
|
||||
}
|
||||
// Find out if island is locked
|
||||
// TODO: Fire event
|
||||
|
||||
Island island = bSkyBlock.getIslands().getIsland(foundWarp);
|
||||
boolean pvp = false;
|
||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||
pvp = true;
|
||||
}
|
||||
// Find out which direction the warp is facing
|
||||
Block b = warpSpot.getBlock();
|
||||
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
|
||||
BlockFace directionFacing = s.getFacing();
|
||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||
Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
|
||||
if ((Util.isSafeLocation(inFront))) {
|
||||
warpPlayer(player, inFront, foundWarp, directionFacing, pvp);
|
||||
return;
|
||||
} else if (b.getType().equals(Material.WALL_SIGN) && Util.isSafeLocation(oneDown)) {
|
||||
// Try one block down if this is a wall sign
|
||||
warpPlayer(player, oneDown, foundWarp, directionFacing, pvp);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Warp has been removed
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.DoesNotExist"));
|
||||
plugin.getWarpSigns().removeWarp(warpSpot);
|
||||
return;
|
||||
}
|
||||
if (!(Util.isSafeLocation(warpSpot))) {
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player.getUniqueId()).get("warps.error.NotSafe"));
|
||||
// WALL_SIGN's will always be unsafe if the place in front is obscured.
|
||||
if (b.getType().equals(Material.SIGN_POST)) {
|
||||
plugin.getLogger().warning(
|
||||
"Unsafe warp found at " + warpSpot.toString() + " owned by " + bSkyBlock.getPlayers().getName(foundWarp));
|
||||
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(),
|
||||
warpSpot.getBlockZ() + 0.5D);
|
||||
player.teleport(actualWarp);
|
||||
if (pvp) {
|
||||
Util.sendMessage(player, ChatColor.BOLD + "" + ChatColor.RED + bSkyBlock.getLocale(player.getUniqueId()).get("igs." + SettingsFlag.PVP_OVERWORLD + " " + bSkyBlock.getLocale(player.getUniqueId()).get("igs.Allowed")));
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||
} else {
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[]{"[player]", "Warp to player's warp sign"};
|
||||
}
|
||||
}.alias("warp"));
|
||||
|
||||
// island warps command
|
||||
bSkyBlock.addSubCommand(new ArgumentHandler("island") {
|
||||
|
||||
@Override
|
||||
public CanUseResp canUse(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "island.warp");
|
||||
return new CanUseResp(true);
|
||||
}
|
||||
return new CanUseResp(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
if (plugin.getWarpSigns().listWarps().isEmpty()) {
|
||||
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(player.getUniqueId()).get("warps.error.no-warps-yet"));
|
||||
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.addwarp") && bSkyBlock.getIslands().playerIsOnIsland(player)) {
|
||||
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale().get("warps.warpTip"));
|
||||
}
|
||||
} else {
|
||||
player.openInventory(plugin.getWarpPanel().getWarpPanel(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[]{"", "View warps"};
|
||||
}
|
||||
}.alias("warps"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Warps a player to a spot in front of a sign
|
||||
* @param player
|
||||
* @param inFront
|
||||
* @param foundWarp
|
||||
* @param directionFacing
|
||||
*/
|
||||
private void warpPlayer(Player player, Location inFront, UUID foundWarp, BlockFace directionFacing, boolean pvp) {
|
||||
// convert blockface to angle
|
||||
float yaw = blockFaceToFloat(directionFacing);
|
||||
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
|
||||
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
||||
player.teleport(actualWarp);
|
||||
if (pvp) {
|
||||
Util.sendMessage(player, ChatColor.BOLD + "" + ChatColor.RED + bSkyBlock.getLocale(player.getUniqueId()).get("igs." + SettingsFlag.PVP_OVERWORLD + " " + bSkyBlock.getLocale(player.getUniqueId()).get("igs.allowed")));
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||
|
||||
} else {
|
||||
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||
|
||||
}
|
||||
Player warpOwner = plugin.getServer().getPlayer(foundWarp);
|
||||
if (warpOwner != null && !warpOwner.equals(player)) {
|
||||
Util.sendMessage(warpOwner, plugin.getLocale(foundWarp).get("warps.PlayerWarped").replace("[name]", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts block face direction to radial degrees. Returns 0 if block face
|
||||
* is not radial.
|
||||
*
|
||||
* @param face
|
||||
* @return degrees
|
||||
*/
|
||||
public float blockFaceToFloat(BlockFace face) {
|
||||
switch (face) {
|
||||
case EAST:
|
||||
return 90F;
|
||||
case EAST_NORTH_EAST:
|
||||
return 67.5F;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 0F;
|
||||
case NORTH:
|
||||
return 0F;
|
||||
case NORTH_EAST:
|
||||
return 45F;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 22.5F;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 337.5F;
|
||||
case NORTH_WEST:
|
||||
return 315F;
|
||||
case SOUTH:
|
||||
return 180F;
|
||||
case SOUTH_EAST:
|
||||
return 135F;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 157.5F;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 202.5F;
|
||||
case SOUTH_WEST:
|
||||
return 225F;
|
||||
case WEST:
|
||||
return 270F;
|
||||
case WEST_NORTH_WEST:
|
||||
return 292.5F;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 247.5F;
|
||||
default:
|
||||
return 0F;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package bskyblock.addin.warps.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import bskyblock.addin.warps.Warp;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public class WarpCommand extends CompositeCommand {
|
||||
|
||||
private Warp plugin;
|
||||
|
||||
public WarpCommand(Warp plugin, CompositeCommand bsbIslandCmd) {
|
||||
super(bsbIslandCmd, "warp");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||
this.setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (args.size() == 1) {
|
||||
// Warp somewhere command
|
||||
final Set<UUID> warpList = plugin.getWarpSignsManager().listWarps();
|
||||
if (warpList.isEmpty()) {
|
||||
user.sendMessage("warps.errorNoWarpsYet");
|
||||
user.sendMessage("warps.warpTip");
|
||||
return true;
|
||||
} else {
|
||||
// Check if this is part of a name
|
||||
UUID foundWarp = null;
|
||||
for (UUID warp : warpList) {
|
||||
if (warp == null)
|
||||
continue;
|
||||
if (getPlayers().getName(warp).toLowerCase().equals(args.get(0).toLowerCase())) {
|
||||
foundWarp = warp;
|
||||
break;
|
||||
} else if (getPlayers().getName(warp).toLowerCase().startsWith(args.get(0).toLowerCase())) {
|
||||
foundWarp = warp;
|
||||
}
|
||||
}
|
||||
if (foundWarp == null) {
|
||||
user.sendMessage("warps.error.DoesNotExist");
|
||||
return true;
|
||||
} else {
|
||||
// Warp exists!
|
||||
plugin.getWarpSignsManager().warpPlayer(user, foundWarp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package bskyblock.addin.warps.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addin.warps.Warp;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
public class WarpsCommand extends CompositeCommand {
|
||||
|
||||
private Warp plugin;
|
||||
|
||||
public WarpsCommand(Warp plugin, CompositeCommand bsbIslandCmd) {
|
||||
super(bsbIslandCmd, "warps");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see us.tastybento.bskyblock.api.commands.BSBCommand#setup()
|
||||
*/
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||
this.setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (plugin.getWarpSignsManager().listWarps().isEmpty()) {
|
||||
user.sendMessage("warps.error.no-warps-yet");
|
||||
user.sendMessage("warps.warpTip");
|
||||
} else {
|
||||
plugin.getWarpPanelManager().showWarpPanel(user,0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package bskyblock.addin.warps.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import bskyblock.addin.warps.Warp;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.AbstractLocaleManager;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public class LocaleManager extends AbstractLocaleManager {
|
||||
|
||||
public LocaleManager(Warp plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BSBLocale getLocale(UUID player) {
|
||||
//getLogger().info("DEBUG: " + player);
|
||||
//getLogger().info("DEBUG: " + getPlayers() == null ? "Players is null":"Players in not null");
|
||||
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player));
|
||||
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player).getLocale());
|
||||
String locale = BSkyBlock.getPlugin().getPlayers().getPlayer(player).getLocale();
|
||||
if(locale.isEmpty() || !getLocales().containsKey(locale)) return getLocales().get(Settings.defaultLanguage);
|
||||
|
||||
return getLocales().get(locale);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import org.bukkit.Location;
|
|||
|
||||
import us.tastybento.bskyblock.database.objects.DataObject;
|
||||
|
||||
public class Warps extends DataObject {
|
||||
public class WarpsDO extends DataObject {
|
||||
|
||||
private String uniqueId = "warps";
|
||||
private Map<UUID, Location> warpSigns = new HashMap<>();
|
||||
|
@ -33,7 +33,7 @@ public class Warps extends DataObject {
|
|||
this.warpSigns = warpSigns;
|
||||
}
|
||||
|
||||
public Warps save(Map<UUID, Location> warpList) {
|
||||
public WarpsDO save(Map<UUID, Location> warpList) {
|
||||
this.warpSigns = warpList;
|
||||
return this;
|
||||
}
|
Loading…
Reference in New Issue