mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-22 10:35:52 +01:00
Added check for island level if the Level addon exists.
This commit is contained in:
parent
dc5394ede2
commit
6453f25655
5
pom.xml
5
pom.xml
@ -53,6 +53,11 @@
|
|||||||
<artifactId>bskyblock</artifactId>
|
<artifactId>bskyblock</artifactId>
|
||||||
<version>LATEST</version>
|
<version>LATEST</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>bskyblock.addon</groupId>
|
||||||
|
<artifactId>Level</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package bskyblock.addin.warps;
|
package bskyblock.addin.warps;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import bskyblock.addin.warps.commands.WarpCommand;
|
import bskyblock.addin.warps.commands.WarpCommand;
|
||||||
import bskyblock.addin.warps.commands.WarpsCommand;
|
import bskyblock.addin.warps.commands.WarpsCommand;
|
||||||
import bskyblock.addin.warps.config.PluginConfig;
|
import bskyblock.addin.warps.config.PluginConfig;
|
||||||
@ -15,6 +17,8 @@ import us.tastybento.bskyblock.config.Settings;
|
|||||||
*/
|
*/
|
||||||
public class Warp extends Addon {
|
public class Warp extends Addon {
|
||||||
|
|
||||||
|
private static final String BSKYBLOCK_LEVEL = "BSkyBlock-Level";
|
||||||
|
|
||||||
// The BSkyBlock plugin instance.
|
// The BSkyBlock plugin instance.
|
||||||
private BSkyBlock bSkyBlock;
|
private BSkyBlock bSkyBlock;
|
||||||
|
|
||||||
@ -24,6 +28,9 @@ public class Warp extends Addon {
|
|||||||
// Warps signs object
|
// Warps signs object
|
||||||
private WarpSignsManager warpSignsManager;
|
private WarpSignsManager warpSignsManager;
|
||||||
|
|
||||||
|
// Level addon
|
||||||
|
private Optional<Addon> levelAddon;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Load the plugin's config
|
// Load the plugin's config
|
||||||
@ -46,6 +53,9 @@ public class Warp extends Addon {
|
|||||||
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
|
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
|
||||||
new WarpCommand(this, bsbIslandCmd);
|
new WarpCommand(this, bsbIslandCmd);
|
||||||
new WarpsCommand(this, bsbIslandCmd);
|
new WarpsCommand(this, bsbIslandCmd);
|
||||||
|
|
||||||
|
// Get the level addon if it exists
|
||||||
|
setLevelAddon(getBSkyBlock().getAddonsManager().getAddonByName(BSKYBLOCK_LEVEL));
|
||||||
});
|
});
|
||||||
// Done
|
// Done
|
||||||
}
|
}
|
||||||
@ -69,4 +79,12 @@ public class Warp extends Addon {
|
|||||||
return warpSignsManager;
|
return warpSignsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Addon> getLevelAddon() {
|
||||||
|
return levelAddon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevelAddon(Optional<Addon> levelAddon) {
|
||||||
|
this.levelAddon = levelAddon;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,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 = false;
|
||||||
private static final int PANEL_MAX_SIZE = 52;
|
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
|
||||||
@ -87,6 +87,11 @@ public class WarpPanelManager {
|
|||||||
return playerSkull;
|
return playerSkull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the warp panel for the user
|
||||||
|
* @param user
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
public void showWarpPanel(User user, int index) {
|
public void showWarpPanel(User user, int index) {
|
||||||
List<UUID> warps = new ArrayList<>(plugin.getWarpSignsManager().getSortedWarps());
|
List<UUID> warps = new ArrayList<>(plugin.getWarpSignsManager().getSortedWarps());
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -99,7 +104,10 @@ public class WarpPanelManager {
|
|||||||
}
|
}
|
||||||
// TODO use when locales are done.
|
// 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", "[number]", String.valueOf(index + 1)));
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title") + " " + 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);
|
||||||
|
@ -16,7 +16,6 @@ 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;
|
||||||
@ -31,16 +30,17 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
|
||||||
|
import bskyblock.addin.warps.config.Settings;
|
||||||
import bskyblock.addin.warps.database.object.WarpsDO;
|
import bskyblock.addin.warps.database.object.WarpsDO;
|
||||||
import bskyblock.addin.warps.event.WarpInitiateEvent;
|
import bskyblock.addin.warps.event.WarpInitiateEvent;
|
||||||
import bskyblock.addin.warps.event.WarpListEvent;
|
import bskyblock.addin.warps.event.WarpListEvent;
|
||||||
import bskyblock.addin.warps.event.WarpRemoveEvent;
|
import bskyblock.addin.warps.event.WarpRemoveEvent;
|
||||||
|
import bskyblock.addon.level.Level;
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.commands.User;
|
import us.tastybento.bskyblock.api.commands.User;
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
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.generators.IslandWorld;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
|
|
||||||
@ -51,7 +51,8 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WarpSignsManager implements Listener {
|
public class WarpSignsManager implements Listener {
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = false;
|
||||||
|
private static final boolean DEBUG2 = false;
|
||||||
private BSkyBlock bSkyBlock;
|
private BSkyBlock bSkyBlock;
|
||||||
// Map of all warps stored as player, warp sign Location
|
// Map of all warps stored as player, warp sign Location
|
||||||
private Map<UUID, Location> warpList;
|
private Map<UUID, Location> warpList;
|
||||||
@ -224,6 +225,7 @@ public class WarpSignsManager implements Listener {
|
|||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (warpList.size() < 100) {
|
if (warpList.size() < 100) {
|
||||||
// TEST CODE
|
// TEST CODE
|
||||||
for (int i = 0; i < 300; i++) {
|
for (int i = 0; i < 300; i++) {
|
||||||
@ -238,7 +240,7 @@ public class WarpSignsManager implements Listener {
|
|||||||
sign.update();
|
sign.update();
|
||||||
warpList.put(rand, new Location(IslandWorld.getIslandWorld(), x, 120, z));
|
warpList.put(rand, new Location(IslandWorld.getIslandWorld(), x, 120, z));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -290,29 +292,36 @@ public class WarpSignsManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
|
||||||
public void onSignWarpCreate(SignChangeEvent e) {
|
public void onSignWarpCreate(SignChangeEvent e) {
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: SignChangeEvent called");
|
plugin.getLogger().info("DEBUG: SignChangeEvent called");
|
||||||
String title = e.getLine(0);
|
String title = e.getLine(0);
|
||||||
User player = User.getInstance(e.getPlayer());
|
User player = User.getInstance(e.getPlayer());
|
||||||
if (player.getWorld().equals(IslandWorld.getIslandWorld()) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
if (player.getWorld().equals(IslandWorld.getIslandWorld()) || player.getWorld().equals(IslandWorld.getNetherWorld())) {
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: Correct world");
|
plugin.getLogger().info("DEBUG: Correct world");
|
||||||
if (e.getBlock().getType().equals(Material.SIGN_POST) || e.getBlock().getType().equals(Material.WALL_SIGN)) {
|
if (e.getBlock().getType().equals(Material.SIGN_POST) || e.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
|
plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
|
||||||
// Check if someone is changing their own sign
|
// Check if someone is changing their own sign
|
||||||
// This should never happen !!
|
// This should never happen !!
|
||||||
if (title.equalsIgnoreCase(plugin.getConfig().getString("welcomeLine"))) {
|
if (title.equalsIgnoreCase(plugin.getConfig().getString("welcomeLine"))) {
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: Welcome sign detected");
|
plugin.getLogger().info("DEBUG: Welcome sign detected");
|
||||||
// Welcome sign detected - check permissions
|
// Welcome sign detected - check permissions
|
||||||
if (!(player.hasPermission(us.tastybento.bskyblock.config.Settings.PERMPREFIX + "island.addwarp"))) {
|
if (!(player.hasPermission(us.tastybento.bskyblock.config.Settings.PERMPREFIX + "island.addwarp"))) {
|
||||||
player.sendMessage("warps.error.no-permission");
|
player.sendMessage("warps.error.no-permission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
if (plugin.getLevelAddon().isPresent()) {
|
||||||
if(!(ASkyBlockAPI.getInstance().getLongIslandLevel(player.getUniqueId()) > Settings.warpLevelsRestriction)){
|
Level lev = (Level) plugin.getLevelAddon().get();
|
||||||
player.sendMessage(ChatColor.RED + "warps.error.NotEnoughLevel"));
|
if (lev.getIslandLevel(player.getUniqueId()) < Settings.warpLevelRestriction) {
|
||||||
|
player.sendMessage("warps.error.NotEnoughLevel");
|
||||||
|
player.sendLegacyMessage("Your level is only " + lev.getIslandLevel(player.getUniqueId()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check that the player is on their island
|
// Check that the player is on their island
|
||||||
if (!(bSkyBlock.getIslands().playerIsOnIsland(player))) {
|
if (!(bSkyBlock.getIslands().playerIsOnIsland(player))) {
|
||||||
player.sendMessage("warps.error.not-on-island");
|
player.sendMessage("warps.error.not-on-island");
|
||||||
@ -459,15 +468,15 @@ public class WarpSignsManager implements Listener {
|
|||||||
if (signLocation == null) {
|
if (signLocation == null) {
|
||||||
plugin.getWarpSignsManager().removeWarp(uuid);
|
plugin.getWarpSignsManager().removeWarp(uuid);
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG)
|
if (DEBUG2)
|
||||||
Bukkit.getLogger().info("DEBUG: getting sign text");
|
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)
|
if (DEBUG2)
|
||||||
Bukkit.getLogger().info("DEBUG: sign is a sign");
|
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)
|
if (DEBUG2)
|
||||||
Bukkit.getLogger().info("DEBUG: " + result.toString());
|
Bukkit.getLogger().info("DEBUG: " + result.toString());
|
||||||
}
|
}
|
||||||
// Clean up - remove the [WELCOME] line
|
// Clean up - remove the [WELCOME] line
|
||||||
@ -500,7 +509,7 @@ public class WarpSignsManager implements Listener {
|
|||||||
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
||||||
user.teleport(actualWarp);
|
user.teleport(actualWarp);
|
||||||
if (pvp) {
|
if (pvp) {
|
||||||
user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.allowed"));
|
//user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.allowed"));
|
||||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||||
} else {
|
} else {
|
||||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||||
@ -576,10 +585,10 @@ 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 (island != null) {
|
if (island != null) {
|
||||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
//if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
// || (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||||
pvp = true;
|
// 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();
|
||||||
@ -617,7 +626,7 @@ public class WarpSignsManager implements Listener {
|
|||||||
warpSpot.getBlockZ() + 0.5D);
|
warpSpot.getBlockZ() + 0.5D);
|
||||||
user.teleport(actualWarp);
|
user.teleport(actualWarp);
|
||||||
if (pvp) {
|
if (pvp) {
|
||||||
user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.Allowed"));
|
//user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.Allowed"));
|
||||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||||
} else {
|
} else {
|
||||||
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||||
|
Loading…
Reference in New Issue
Block a user