1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-29 14:15:23 +01:00

Merge remote-tracking branch 'origin/develop'

Conflicts:
	pom.xml
This commit is contained in:
tastybento 2020-12-30 23:07:49 -08:00
commit db3b1fe5cf
8 changed files with 98 additions and 50 deletions

View File

@ -58,15 +58,15 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0</bentobox.version>
<spigot.version>1.16.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.15.4</bentobox.version>
<level.version>1.5.0</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.10.1</build.version>
<build.version>1.10.2</build.version>
</properties>
<!-- Profiles will allow to automatically change build version. -->

View File

@ -186,7 +186,12 @@ public class WarpSignsManager {
// Load into map
if (warpsData != null) {
warpsData.getWarpSigns().forEach((k,v) -> {
if (k != null && k.getWorld() != null && k.getBlock().getType().name().contains("SIGN")) {
if (k != null && k.getWorld() != null) {
if (k.getWorld().isChunkLoaded(k.getBlockX() >> 4, k.getBlockZ() >> 4)
&& !k.getBlock().getType().name().contains("SIGN")) {
return;
}
// Add to map
getWarpMap(k.getWorld()).put(v, k);
}
@ -327,13 +332,17 @@ public class WarpSignsManager {
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
inFront.getBlockZ() + 0.5D, yaw, 30F);
Util.teleportAsync(user.getPlayer(), actualWarp, TeleportCause.COMMAND);
User warpOwner = User.getInstance(signOwner);
// Hide invisible players
if (warpOwner.isOnline() && !warpOwner.getPlayer().canSee(user.getPlayer())) {
return;
}
if (pvp) {
user.sendMessage("protection.flags.PVP_OVERWORLD.active");
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(signOwner);
}
if (!warpOwner.equals(user)) {
warpOwner.sendMessage("warps.player-warped", "[name]", user.getName());
}

View File

@ -17,7 +17,6 @@ import world.bentobox.warps.Warp;
* The /is warp <name> command
*
* @author tastybento
*
*/
public class WarpCommand extends DelayedTeleportCommand {
@ -52,12 +51,22 @@ public class WarpCommand extends DelayedTeleportCommand {
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
return false;
} else {
// Check if this is part of a name
UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))
|| getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null);
// Attemp to find warp with exact player's name
UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))).findFirst().orElse(null);
if (foundWarp == null) {
user.sendMessage("warps.error.does-not-exist");
return false;
// Atempt to find warp which starts with the given name
UUID foundAlernativeWarp = warpList.stream().filter(u -> getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null);
if (foundAlernativeWarp == null) {
user.sendMessage("warps.error.does-not-exist");
return false;
} else {
// Alternative warp found!
this.delayCommand(user, () -> addon.getWarpSignsManager().warpPlayer(world, user, foundAlernativeWarp));
return true;
}
} else {
// Warp exists!
this.delayCommand(user, () -> addon.getWarpSignsManager().warpPlayer(world, user, foundWarp));

View File

@ -1,12 +1,11 @@
package world.bentobox.warps.listeners;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
@ -16,9 +15,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.scheduler.BukkitRunnable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamKickEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamLeaveEvent;
import world.bentobox.bentobox.api.events.addon.AddonEvent;
import world.bentobox.bentobox.api.events.team.TeamKickEvent;
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.warps.Warp;
@ -44,20 +46,49 @@ public class WarpSignsListener implements Listener {
this.plugin = addon.getPlugin();
}
@EventHandler(priority = EventPriority.NORMAL)
public void onChunkLoad(ChunkLoadEvent event) {
// Delay to wait the chunk to be fully loaded
new BukkitRunnable() {
@Override
public void run() {
boolean changed = false;
Iterator<Map.Entry<UUID, Location>> iterator =
addon.getWarpSignsManager().getWarpMap(event.getWorld()).entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, Location> entry = iterator.next();
UUID uuid = entry.getKey();
Location location = entry.getValue();
if (event.getChunk().getX() == location.getBlockX() >> 4
&& event.getChunk().getZ() == location.getBlockZ() >> 4
&& !Tag.SIGNS.isTagged(location.getBlock().getType())) {
iterator.remove();
// Remove sign from warp panel cache
addon.getWarpPanelManager().removeWarp(event.getWorld(), uuid);
changed = true;
}
}
if (changed) {
addon.getWarpSignsManager().saveWarpList();
}
}
}.runTask(plugin);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(TeamLeaveEvent e) {
// Remove any warp signs from this game mode
addon.getWarpSignsManager().removeWarp(e.getIsland().getWorld(), e.getPlayerUUID());
User.getInstance(e.getPlayerUUID()).sendMessage("warps.deactivate");
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(TeamKickEvent e) {
// Remove any warp signs from this game mode
addon.getWarpSignsManager().removeWarp(e.getIsland().getWorld(), e.getPlayerUUID());
User.getInstance(e.getPlayerUUID()).sendMessage("warps.deactivate");
}
/**
* Checks to see if a sign has been broken
* @param e - event
@ -197,6 +228,13 @@ public class WarpSignsListener implements Listener {
for (int i = 1; i<4; i++) {
e.setLine(i, ChatColor.translateAlternateColorCodes('&', e.getLine(i)));
}
Map<String, Object> keyValues = new HashMap<>();
keyValues.put("eventName", "WarpCreateEvent");
keyValues.put("targetPlayer", user.getUniqueId());
keyValues.put("location", Util.getStringLocation(b.getLocation()));
new AddonEvent().builder().addon(addon).keyValues(keyValues).build();
}
// Else null player
}

View File

@ -2,7 +2,7 @@ name: Warps
main: world.bentobox.warps.Warp
version: ${version}${build.number}
icon: OAK_SIGN
api-version: 1.14
api-version: 1.15.4
authors: tastybento

View File

@ -1,31 +1,27 @@
###########################################################################################
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
# the one at http://yaml-online-parser.appspot.com #
###########################################################################################
warp:
help:
description: "Oyuncunun bölge tabelası."
parameters: <name>
warps:
---
warp:
help:
description: Oyuncunun bölge tabelası.
parameters: "<name>"
warps:
deactivate: "&cEski ada warpı silindi!"
error:
does-not-exist: "&4Malasef sorun oluştu. Tekrar dene."
error:
does-not-exist: "&cÜzgünüm. Böyle bir bölge artık yok!"
no-permission: "&4Buna yetkin yok!"
not-safe: "&4Ada bölgesi güvenli değil!"
no-remove: "&4Bu tabelayı kıramazsın!"
no-warps-yet: "&4Böyle bir bölge henüz yok."
not-enough-level: "&4Bunu koyman için daha fazla ada leveline ihtiyacın var."
not-on-island: "&4Adanda değilsin."
not-safe: "&4Ada bölgesi güvenli değil!"
your-level-is: "&9Ada levelin &e[level] &9ve &e[required]&9'den fazla olması gerek!"
help:
description: "Bölge panelini açar."
next: "&6Sonraki Sayfa"
help:
description: Bölge panelini açar.
player-warped: "&d[name] &9ada bölgene ışınlandı!"
previous: "&6Önceki sayfa"
sign-removed: "&4Ada tabelası kaldırıldı!"
success: "&9Başarılı!"
title: "&3&lSon&b&lCesurlar &e&lBölgeler &5"
warpTip: "&9Ada warpı açmak için tabelanın en üstüne &e[text] &9yaz!"
success: "&aBaşarılı!"
title: "&dOyuncu bölgeleri &8- &5"
warpTip: "&6Ada bölgesi açmak için tabelanın en üstüne &a[text] &9yaz!"
warpToPlayersSign: "&d[player] &9bölgesine gidiliyor!"
next: "&6Sonraki Sayfa"
previous: "&6Önceki sayfa"
random: "&4Rastgele bölgeye git!"

View File

@ -20,13 +20,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -165,7 +159,8 @@ public class WarpSignsManagerTest {
when(location.getBlockY()).thenReturn(24);
when(location.getBlockZ()).thenReturn(25);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true);
// Block
when(block.getType()).thenReturn(Material.ACACIA_SIGN);
when(block.getLocation()).thenReturn(location);

View File

@ -219,6 +219,7 @@ public class WarpCommandTest {
*/
@Test
public void testExecuteUserStringListOfStringKnownPlayerStartOnly() {
when(pm.getName(any())).thenReturn("tastybento");
warpCommandWarpCompositeCommand();
assertTrue(wc.execute(user, "warp", Collections.singletonList("tAsTy")));
//verify(wsm).warpPlayer(eq(world), eq(user), any());