Skip to content

Commit

Permalink
Improved build protection
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Oct 1, 2020
1 parent 2227168 commit a3e1398
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public boolean isBlockInIslandSphere(int x, int y, int z, int islandSize) {
<= Math.pow(islandSize / 2.0, 2);
}

public boolean isBlockInIslandCircle(int relativeX, int relativeZ, int islandSize) {
public boolean isBlockInIslandCylinder(int relativeX, int relativeZ, int islandSize) {
return (Math.pow(relativeX - islandSize / 2.0, 2) + Math.pow(relativeZ - islandSize / 2.0, 2))
<= Math.pow(islandSize / 2.0, 2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/me/aleksilassila/islands/generation/IslandGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public String getBlockOwnerUUID(int x, int z) {
int relativeX = x - (xIndex * islandSpacing + islandSpacing / 2 - islandSize / 2);
int relativeZ = z - (zIndex * islandSpacing + islandSpacing / 2 - islandSize / 2);

boolean isInside = islands.islandGeneration.isBlockInIslandCircle(relativeX, relativeZ, islandSize);
boolean isInside = islands.islandGeneration.isBlockInIslandCylinder(relativeX + 2, relativeZ + 2, islandSize + 4);

if (!isInside) return null;

Expand Down
9 changes: 6 additions & 3 deletions src/me/aleksilassila/islands/listeners/IslandsListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.aleksilassila.islands.listeners;

import me.aleksilassila.islands.Main;
import me.aleksilassila.islands.utils.Messages;
import me.aleksilassila.islands.utils.Permissions;
import me.aleksilassila.islands.utils.ChatUtils;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void onEntityDamageEvent(EntityDamageByEntityEvent e) {

e.setCancelled(true);

e.getDamager().sendMessage(error("You cannot interact here."));
e.getDamager().sendMessage(Messages.error.NOT_TRUSTED);
}
}
}
Expand All @@ -151,7 +152,7 @@ public void onPlayerInteract(PlayerInteractEvent e) {

e.setCancelled(true);

e.getPlayer().sendMessage(error("You cannot interact here."));
e.getPlayer().sendMessage(Messages.error.NOT_TRUSTED);
}
}
}
Expand All @@ -161,6 +162,7 @@ public void onPlayerInteract(PlayerInteractEvent e) {
private void onBlockPlace(BlockPlaceEvent e) {
if (e.isCancelled()) return;
if (e.getPlayer().hasPermission(Permissions.bypass.interactEverywhere)) return;

if (e.getBlock().getWorld().equals(plugin.islandsWorld)) {
int x = e.getBlock().getX();
int z = e.getBlock().getZ();
Expand All @@ -174,8 +176,9 @@ private void onBlockPlace(BlockPlaceEvent e) {

e.setCancelled(true);

e.getPlayer().sendMessage(error("You cannot interact here."));
if (ownerUUID != null) e.getPlayer().sendMessage(Messages.error.NOT_TRUSTED);
}

}
}
}
1 change: 1 addition & 0 deletions src/me/aleksilassila/islands/utils/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class error {
public static final String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome.");
public static final String ISLAND_NOT_FOUND = error("404 - Home not found.");
public static final String HOME_NOT_FOUND = error("404 - Home not found :(");
public static final String NOT_TRUSTED = error("You need owner's permission to interact here.");

public static String COOLDOWN(int remainingTime) {
return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting.");
Expand Down

0 comments on commit a3e1398

Please sign in to comment.