mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2025-02-17 21:01:34 +01:00
Finished warps addon.
This commit is contained in:
parent
9b1f8bd14c
commit
dc5394ede2
@ -3,27 +3,26 @@
|
|||||||
# the one at http://yaml-online-parser.appspot.com #
|
# the one at http://yaml-online-parser.appspot.com #
|
||||||
###########################################################################################
|
###########################################################################################
|
||||||
|
|
||||||
### Credits ###
|
|
||||||
# Tastybento: maintainer
|
|
||||||
# Poslovitch: maintainer
|
|
||||||
#
|
|
||||||
# This translation is adapted to version : [alpha-0.0.1]
|
|
||||||
|
|
||||||
warps:
|
warps:
|
||||||
welcomeLine: "[Welcome]"
|
removed: "&CWarp sign removed"
|
||||||
removed: "Warp sign removed"
|
success: "&ASuccess!"
|
||||||
success: "Success!"
|
sign-removed: "&CWarp sign removed!"
|
||||||
sign-removed: "Warp sign removed!"
|
|
||||||
title: "Warp Signs"
|
title: "Warp Signs"
|
||||||
previous: "Previous page"
|
previous: "&6Previous page"
|
||||||
next: "Next page"
|
next: "&6Next page"
|
||||||
warpToPlayersSign: "Warping to [player]'s sign"
|
warpToPlayersSign: "&6Warping to [player]'s sign"
|
||||||
warpTip: "Place a warp sign with [Welcome] on the top"
|
warpTip: "&6Place a warp sign with [Welcome] on the top"
|
||||||
error:
|
error:
|
||||||
no-remove: "You cannot remove that sign!"
|
no-remove: "&CYou cannot remove that sign!"
|
||||||
not-enough-level: "Your island level is not high enough!"
|
not-enough-level: "&CYour island level is not high enough!"
|
||||||
no-permission: "You do not have permission to do that!"
|
no-permission: "&CYou do not have permission to do that!"
|
||||||
not-on-island: "You must be on your island to do that!"
|
not-on-island: "&CYou must be on your island to do that!"
|
||||||
duplicate: "Duplicate sign placed"
|
duplicate: "&CDuplicate sign placed"
|
||||||
no-warps-yet: "There are no warps available yet"
|
no-warps-yet: "&CThere are no warps available yet"
|
||||||
|
help:
|
||||||
|
description: "open the warps panel"
|
||||||
|
warp:
|
||||||
|
help:
|
||||||
|
parameters: "<name>"
|
||||||
|
description: "warp to the player's warp sign"
|
||||||
|
|
@ -21,7 +21,7 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
|||||||
public class WarpPanelManager {
|
public class WarpPanelManager {
|
||||||
|
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
private static final int PANEL_MAX_SIZE = 47;
|
private static final int PANEL_MAX_SIZE = 52;
|
||||||
private Warp plugin;
|
private Warp plugin;
|
||||||
// This is a cache of heads, so they don't need to be created everytime
|
// This is a cache of heads, so they don't need to be created everytime
|
||||||
private HashMap<UUID, PanelItem> cachedWarps;
|
private HashMap<UUID, PanelItem> cachedWarps;
|
||||||
@ -50,9 +50,9 @@ public class WarpPanelManager {
|
|||||||
|
|
||||||
private PanelItem getPanelItem(UUID warpOwner) {
|
private PanelItem getPanelItem(UUID warpOwner) {
|
||||||
return new PanelItemBuilder()
|
return new PanelItemBuilder()
|
||||||
|
.setIcon(getSkull(warpOwner))
|
||||||
.setName(plugin.getBSkyBlock().getPlayers().getName(warpOwner))
|
.setName(plugin.getBSkyBlock().getPlayers().getName(warpOwner))
|
||||||
.setDescription(plugin.getWarpSignsManager().getSignText(warpOwner))
|
.setDescription(plugin.getWarpSignsManager().getSignText(warpOwner))
|
||||||
.setIcon(getSkull(warpOwner))
|
|
||||||
.setClickHandler(new ClickHandler() {
|
.setClickHandler(new ClickHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,7 +97,9 @@ public class WarpPanelManager {
|
|||||||
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
|
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
|
||||||
index = warps.size() / PANEL_MAX_SIZE;
|
index = warps.size() / PANEL_MAX_SIZE;
|
||||||
}
|
}
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title"));
|
// TODO use when locales are done.
|
||||||
|
//PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title", "[number]", String.valueOf(index + 1)));
|
||||||
|
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title") + " " + String.valueOf(index + 1));
|
||||||
int i = index * PANEL_MAX_SIZE;
|
int i = index * PANEL_MAX_SIZE;
|
||||||
for (; i < (index * PANEL_MAX_SIZE + PANEL_MAX_SIZE) && i < warps.size(); i++) {
|
for (; i < (index * PANEL_MAX_SIZE + PANEL_MAX_SIZE) && i < warps.size(); i++) {
|
||||||
UUID owner = warps.get(i);
|
UUID owner = warps.get(i);
|
||||||
@ -117,6 +119,7 @@ public class WarpPanelManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(User user, ClickType click) {
|
public boolean onClick(User user, ClickType click) {
|
||||||
|
user.closeInventory();
|
||||||
showWarpPanel(user, panelNum+1);
|
showWarpPanel(user, panelNum+1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -126,12 +129,13 @@ public class WarpPanelManager {
|
|||||||
if (i > PANEL_MAX_SIZE) {
|
if (i > PANEL_MAX_SIZE) {
|
||||||
// Previous
|
// Previous
|
||||||
panelBuilder.addItem(new PanelItemBuilder()
|
panelBuilder.addItem(new PanelItemBuilder()
|
||||||
.setName("Next")
|
.setName("Previous")
|
||||||
.setIcon(new ItemStack(Material.SIGN))
|
.setIcon(new ItemStack(Material.SIGN))
|
||||||
.setClickHandler(new ClickHandler() {
|
.setClickHandler(new ClickHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(User user, ClickType click) {
|
public boolean onClick(User user, ClickType click) {
|
||||||
|
user.closeInventory();
|
||||||
showWarpPanel(user, panelNum-1);
|
showWarpPanel(user, panelNum-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -140,4 +144,9 @@ public class WarpPanelManager {
|
|||||||
}
|
}
|
||||||
panelBuilder.build();
|
panelBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void remove(UUID uuid) {
|
||||||
|
cachedWarps.remove(uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,14 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -222,6 +224,21 @@ public class WarpSignsManager implements Listener {
|
|||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (warpList.size() < 100) {
|
||||||
|
// TEST CODE
|
||||||
|
for (int i = 0; i < 300; i++) {
|
||||||
|
UUID rand = UUID.randomUUID();
|
||||||
|
int x = RandomUtils.nextInt(100000) - RandomUtils.nextInt(100000);
|
||||||
|
int z = RandomUtils.nextInt(100000) - RandomUtils.nextInt(100000);
|
||||||
|
Block b = IslandWorld.getIslandWorld().getBlockAt(x, 119, z);
|
||||||
|
b.setType(Material.STONE);
|
||||||
|
b.getRelative(BlockFace.UP).setType(Material.SIGN_POST);
|
||||||
|
Sign sign = (Sign)b.getRelative(BlockFace.UP).getState();
|
||||||
|
sign.setLine(0, ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"));
|
||||||
|
sign.update();
|
||||||
|
warpList.put(rand, new Location(IslandWorld.getIslandWorld(), x, 120, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,20 +404,20 @@ public class WarpSignsManager implements Listener {
|
|||||||
Entry<UUID, Location> en = it.next();
|
Entry<UUID, Location> en = it.next();
|
||||||
if (en.getValue().equals(loc)) {
|
if (en.getValue().equals(loc)) {
|
||||||
// Inform player
|
// Inform player
|
||||||
User p = User.getInstance(plugin.getServer().getPlayer(en.getKey()));
|
User user = User.getInstance(plugin.getServer().getPlayer(en.getKey()));
|
||||||
if (p != null) {
|
if (user != null) {
|
||||||
// Inform the player
|
// Inform the player
|
||||||
p.sendMessage("warps.sign-removed");
|
user.sendMessage("warps.sign-removed");
|
||||||
}
|
}
|
||||||
|
plugin.getWarpPanelManager().remove(en.getKey());
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveWarpList();
|
saveWarpList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a warp when the welcome sign is destroyed. Called by
|
* Remove warp sign owned by UUID
|
||||||
* WarpSigns.java.
|
|
||||||
*
|
*
|
||||||
* @param uuid
|
* @param uuid
|
||||||
*/
|
*/
|
||||||
@ -410,6 +427,7 @@ public class WarpSignsManager implements Listener {
|
|||||||
warpList.remove(uuid);
|
warpList.remove(uuid);
|
||||||
}
|
}
|
||||||
saveWarpList();
|
saveWarpList();
|
||||||
|
plugin.getWarpPanelManager().remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -440,12 +458,31 @@ public class WarpSignsManager implements Listener {
|
|||||||
Location signLocation = getWarp(uuid);
|
Location signLocation = getWarp(uuid);
|
||||||
if (signLocation == null) {
|
if (signLocation == null) {
|
||||||
plugin.getWarpSignsManager().removeWarp(uuid);
|
plugin.getWarpSignsManager().removeWarp(uuid);
|
||||||
} else
|
} else {
|
||||||
|
if (DEBUG)
|
||||||
|
Bukkit.getLogger().info("DEBUG: getting sign text");
|
||||||
// Get the sign info if it exists
|
// Get the sign info if it exists
|
||||||
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
|
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||||
|
if (DEBUG)
|
||||||
|
Bukkit.getLogger().info("DEBUG: sign is a sign");
|
||||||
Sign sign = (Sign)signLocation.getBlock().getState();
|
Sign sign = (Sign)signLocation.getBlock().getState();
|
||||||
result.addAll(Arrays.asList(sign.getLines()));
|
result.addAll(Arrays.asList(sign.getLines()));
|
||||||
|
if (DEBUG)
|
||||||
|
Bukkit.getLogger().info("DEBUG: " + result.toString());
|
||||||
}
|
}
|
||||||
|
// Clean up - remove the [WELCOME] line
|
||||||
|
result.remove(0);
|
||||||
|
// Remove any trailing blank lines
|
||||||
|
ListIterator<String> it = result.listIterator(result.size());
|
||||||
|
while (it.hasPrevious()) {
|
||||||
|
String line = it.previous();
|
||||||
|
if (line.isEmpty())
|
||||||
|
it.remove();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,9 +575,11 @@ public class WarpSignsManager implements Listener {
|
|||||||
|
|
||||||
Island island = plugin.getBSkyBlock().getIslands().getIsland(owner);
|
Island island = plugin.getBSkyBlock().getIslands().getIsland(owner);
|
||||||
boolean pvp = false;
|
boolean pvp = false;
|
||||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
if (island != null) {
|
||||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||||
pvp = true;
|
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||||
|
pvp = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Find out which direction the warp is facing
|
// Find out which direction the warp is facing
|
||||||
Block b = warpSpot.getBlock();
|
Block b = warpSpot.getBlock();
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package bskyblock.addin.warps.commands;
|
package bskyblock.addin.warps.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -9,6 +12,12 @@ import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
|||||||
import us.tastybento.bskyblock.api.commands.User;
|
import us.tastybento.bskyblock.api.commands.User;
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The /is warp <name> command
|
||||||
|
*
|
||||||
|
* @author ben
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class WarpCommand extends CompositeCommand {
|
public class WarpCommand extends CompositeCommand {
|
||||||
|
|
||||||
private Warp plugin;
|
private Warp plugin;
|
||||||
@ -22,6 +31,20 @@ public class WarpCommand extends CompositeCommand {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||||
this.setOnlyPlayer(true);
|
this.setOnlyPlayer(true);
|
||||||
|
this.setParameters("warp.help.parameters");
|
||||||
|
this.setDescription("warp.help.description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<List<String>> tabComplete(User user, String alias, LinkedList<String> args) {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
final Set<UUID> warpList = plugin.getWarpSignsManager().listWarps();
|
||||||
|
|
||||||
|
for (UUID warp : warpList) {
|
||||||
|
options.add(plugin.getBSkyBlock().getPlayers().getName(warp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +30,7 @@ public class WarpsCommand extends CompositeCommand {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||||
this.setOnlyPlayer(true);
|
this.setOnlyPlayer(true);
|
||||||
|
this.setDescription("warps.help.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
Loading…
Reference in New Issue
Block a user