Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup, using bukkit API for colors and logger. #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/main/java/com/wimbli/WorldBorder/BorderCheckTask.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.wimbli.WorldBorder;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.util.Vector;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;


public class BorderCheckTask implements Runnable
Expand Down Expand Up @@ -78,7 +73,7 @@ public static Location checkPlayer(Player player, Location targetLoc, boolean re
Location rideLoc = newLoc.clone();
rideLoc.setY(newLoc.getY() + vertOffset);
if (Config.Debug())
Config.LogWarn("Player was riding a \"" + ride.toString() + "\".");
Config.logWarn("Player was riding a \"" + ride.toString() + "\".");
if (ride instanceof Boat)
{ // boats currently glitch on client when teleported, so crappy workaround is to remove it and spawn a new one
ride.remove();
Expand Down Expand Up @@ -121,8 +116,8 @@ private static Location newLocation(Player player, Location loc, BorderData bord
{
if (Config.Debug())
{
Config.LogWarn((notify ? "Border crossing" : "Check was run") + " in \"" + loc.getWorld().getName() + "\". Border " + border.toString());
Config.LogWarn("Player position X: " + Config.coord.format(loc.getX()) + " Y: " + Config.coord.format(loc.getY()) + " Z: " + Config.coord.format(loc.getZ()));
Config.logWarn((notify ? "Border crossing" : "Check was run") + " in \"" + loc.getWorld().getName() + "\". Border " + border.toString());
Config.logWarn("Player position X: " + Config.coord.format(loc.getX()) + " Y: " + Config.coord.format(loc.getY()) + " Z: " + Config.coord.format(loc.getZ()));
}

Location newLoc = border.correctedPosition(loc, Config.ShapeRound(), player.isFlying());
Expand All @@ -131,7 +126,7 @@ private static Location newLocation(Player player, Location loc, BorderData bord
if (newLoc == null)
{
if (Config.Debug())
Config.LogWarn("Target new location unviable, using spawn or killing player.");
Config.logWarn("Target new location unviable, using spawn or killing player.");
if (Config.getIfPlayerKill())
{
player.setHealth(0.0D);
Expand All @@ -141,7 +136,7 @@ private static Location newLocation(Player player, Location loc, BorderData bord
}

if (Config.Debug())
Config.LogWarn("New position in world \"" + newLoc.getWorld().getName() + "\" at X: " + Config.coord.format(newLoc.getX()) + " Y: " + Config.coord.format(newLoc.getY()) + " Z: " + Config.coord.format(newLoc.getZ()));
Config.logWarn("New position in world \"" + newLoc.getWorld().getName() + "\" at X: " + Config.coord.format(newLoc.getX()) + " Y: " + Config.coord.format(newLoc.getY()) + " Z: " + Config.coord.format(newLoc.getZ()));

if (notify)
player.sendMessage(Config.Message());
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/com/wimbli/WorldBorder/BorderData.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.wimbli.WorldBorder;

import java.util.Arrays;
import java.util.LinkedHashSet;

import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;

import java.util.Arrays;
import java.util.LinkedHashSet;


public class BorderData
{
Expand Down Expand Up @@ -168,7 +168,7 @@ public boolean insideBorder(double xLoc, double zLoc, boolean round)
{
// if this border has a shape override set, use it
if (shapeRound != null)
round = shapeRound.booleanValue();
round = shapeRound;

// square border
if (!round)
Expand All @@ -181,14 +181,7 @@ public boolean insideBorder(double xLoc, double zLoc, boolean round)
double X = Math.abs(x - xLoc);
double Z = Math.abs(z - zLoc);

if (X < DefiniteRectangleX && Z < DefiniteRectangleZ)
return true; // Definitely inside
else if (X >= radiusX || Z >= radiusZ)
return false; // Definitely outside
else if (X * X + Z * Z * radiusSquaredQuotient < radiusXSquared)
return true; // After further calculation, inside
else
return false; // Apparently outside, then
return X < DefiniteRectangleX && Z < DefiniteRectangleZ || !(X >= radiusX || Z >= radiusZ) && X * X + Z * Z * radiusSquaredQuotient < radiusXSquared;
}
}
public boolean insideBorder(double xLoc, double zLoc)
Expand All @@ -212,7 +205,7 @@ public Location correctedPosition(Location loc, boolean round, boolean flying)
{
// if this border has a shape override set, use it
if (shapeRound != null)
round = shapeRound.booleanValue();
round = shapeRound;

double xLoc = loc.getX();
double zLoc = loc.getZ();
Expand Down Expand Up @@ -309,9 +302,7 @@ private boolean isSafeSpot(World world, int X, int Y, int Z, boolean flying)
return safe;

Integer below = (Integer)world.getBlockTypeIdAt(X, Y - 1, Z);
return (safe
&& (!safeOpenBlocks.contains(below) || below == 8 || below == 9) // below target block not open/breathable (so presumably solid), or is water
&& !painfulBlocks.contains(below) // below target block not painful
return ((!safeOpenBlocks.contains(below) || below == 8 || below == 9) && !painfulBlocks.contains(below) // below target block not painful
);
}

Expand Down
Loading