Skip to content

Commit

Permalink
Update to the new Vector system
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Nov 4, 2018
1 parent 0dc5781 commit 9169653
Show file tree
Hide file tree
Showing 49 changed files with 394 additions and 403 deletions.
Expand Up @@ -19,19 +19,19 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import static com.google.common.base.Preconditions.checkNotNull;

import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;

abstract class AbstractBlacklistEvent implements BlacklistEvent {

@Nullable
private final LocalPlayer player;
private final Vector position;
private final BlockVector3 position;
private final Target target;

/**
Expand All @@ -41,7 +41,7 @@ abstract class AbstractBlacklistEvent implements BlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
AbstractBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
AbstractBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
checkNotNull(position);
checkNotNull(target);
this.player = player;
Expand All @@ -61,7 +61,7 @@ public String getCauseName() {
}

@Override
public Vector getPosition() {
public BlockVector3 getPosition() {
return position;
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand Down Expand Up @@ -47,14 +47,14 @@ public interface BlacklistEvent {
*
* @return The position of this event
*/
Vector getPosition();
BlockVector3 getPosition();

/**
* Get the position that should be logged.
*
* @return The position that be logged.
*/
Vector getLoggedPosition();
BlockVector3 getLoggedPosition();

/**
* Get the item type.
Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ abstract class BlockBlacklistEvent extends AbstractBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
BlockBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
BlockBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand All @@ -44,7 +44,7 @@ public String getLoggerMessage() {
}

@Override
public Vector getLoggedPosition() {
public BlockVector3 getLoggedPosition() {
return getPosition();
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class BlockBreakBlacklistEvent extends BlockBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public BlockBreakBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public BlockBreakBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class BlockDispenseBlacklistEvent extends BlockBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public BlockDispenseBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public BlockDispenseBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class BlockInteractBlacklistEvent extends BlockBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public BlockInteractBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public BlockInteractBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class BlockPlaceBlacklistEvent extends BlockBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public BlockPlaceBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public BlockPlaceBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class ItemAcquireBlacklistEvent extends ItemBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public ItemAcquireBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public ItemAcquireBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ abstract class ItemBlacklistEvent extends AbstractBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
ItemBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
ItemBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand All @@ -44,8 +44,8 @@ public String getLoggerMessage() {
}

@Override
public Vector getLoggedPosition() {
return getPlayer() != null ? getPlayer().getLocation().toVector() : getPosition();
public BlockVector3 getLoggedPosition() {
return getPlayer() != null ? getPlayer().getLocation().toVector().toBlockPoint() : getPosition();
}

}
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class ItemDestroyWithBlacklistEvent extends ItemBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public ItemDestroyWithBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public ItemDestroyWithBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand All @@ -49,7 +49,7 @@ public EventType getEventType() {
}

@Override
public Vector getLoggedPosition() {
public BlockVector3 getLoggedPosition() {
// Use the block position instead
return getPosition();
}
Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class ItemDropBlacklistEvent extends ItemBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public ItemDropBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public ItemDropBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.event;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.target.Target;

Expand All @@ -34,7 +34,7 @@ public final class ItemUseBlacklistEvent extends ItemBlacklistEvent {
* @param position The position the event occurred at
* @param target The target of the event
*/
public ItemUseBlacklistEvent(@Nullable LocalPlayer player, Vector position, Target target) {
public ItemUseBlacklistEvent(@Nullable LocalPlayer player, BlockVector3 position, Target target) {
super(player, position, target);
}

Expand Down
Expand Up @@ -19,19 +19,20 @@

package com.sk89q.worldguard.blacklist.logger;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
import com.sk89q.worldguard.blacklist.event.EventType;

import javax.annotation.Nullable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nullable;

public class DatabaseHandler implements LoggerHandler {

private final String dsn;
Expand Down Expand Up @@ -84,7 +85,7 @@ private Connection getConnection() throws SQLException {
* @param item The item used
* @param comment The comment associated with the event
*/
private void logEvent(EventType eventType, @Nullable LocalPlayer player, Vector pos, String item, String comment) {
private void logEvent(EventType eventType, @Nullable LocalPlayer player, BlockVector3 pos, String item, String comment) {
try {
Connection conn = getConnection();
PreparedStatement stmt = conn.prepareStatement(
Expand Down
Expand Up @@ -19,7 +19,7 @@

package com.sk89q.worldguard.blacklist.logger;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
import com.sk89q.worldguard.blacklist.target.Target;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class FileHandler implements LoggerHandler {
private int cacheSize = 10;
private String pathPattern;
private String worldName;
private TreeMap<String,LogFileWriter> writers = new TreeMap<String,LogFileWriter>();
private TreeMap<String,LogFileWriter> writers = new TreeMap<>();

private final Logger logger;

Expand Down Expand Up @@ -217,11 +217,11 @@ private void log(LocalPlayer player, String message, String comment) {
* @param pos The position to get coordinates for
* @return The position's coordinates in human-readable form
*/
private String getCoordinates(Vector pos) {
private String getCoordinates(BlockVector3 pos) {
return "@" + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
}

private void logEvent(BlacklistEvent event, String text, Target target, Vector pos, String comment) {
private void logEvent(BlacklistEvent event, String text, Target target, BlockVector3 pos, String comment) {
log(event.getPlayer(), "Tried to " + text + " " + target.getFriendlyName() + " " + getCoordinates(pos), comment);
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public abstract class SignChestProtection implements ChestProtection {
public abstract Boolean isProtectedSign(Location block, LocalPlayer player);

public boolean isProtected(Location location, LocalPlayer player) {
com.sk89q.worldedit.world.block.BlockState blockState = location.getExtent().getBlock(location.toVector());
com.sk89q.worldedit.world.block.BlockState blockState = location.getExtent().getBlock(location.toVector().toBlockPoint());
if (isChest(blockState.getBlockType())) {
return isProtectedSignAround(location.setY(location.getY() - 1), player);
} else if (blockState.getBlockType() == BlockTypes.SIGN) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private boolean isProtectedSignAround(Location searchBlock, LocalPlayer player)
}

private Boolean isProtectedSignAndChest(Location block, LocalPlayer player) {
if (!isChest(block.getExtent().getBlock(block.setY(block.getY() + 1).toVector()).getBlockType())) {
if (!isChest(block.getExtent().getBlock(block.setY(block.getY() + 1).toVector().toBlockPoint()).getBlockType())) {
return null;
}
return isProtectedSign(block, player);
Expand Down
Expand Up @@ -144,7 +144,7 @@ public Set<ProtectedRegion> getRegions() {
if (regionSet != null) {
return regionSet;
}
regionSet = Collections.unmodifiableSet(new HashSet<ProtectedRegion>(applicable));
regionSet = Collections.unmodifiableSet(new HashSet<>(applicable));
return regionSet;
}

Expand Down

0 comments on commit 9169653

Please sign in to comment.