Skip to content

Commit

Permalink
Probably broke something there
Browse files Browse the repository at this point in the history
  • Loading branch information
ezeiger92 committed Jan 27, 2018
1 parent c290c11 commit 4d19146
Show file tree
Hide file tree
Showing 23 changed files with 482 additions and 207 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/botsko/prism/Prism.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public class Prism extends JavaPlugin {
* they do fall we can attribute them to the player who broke the original
* block.
*/
public ConcurrentHashMap<String, String> preplannedBlockFalls = new ConcurrentHashMap<String, String>();
public ConcurrentHashMap<String, String> preplannedBlockFalls = new ConcurrentHashMap<>();

/**
* VehicleCreateEvents do not include the player/entity that created it, so
* we need to track players right-clicking rails with minecart vehicles, or
* water for boats
*/
public ConcurrentHashMap<String, String> preplannedVehiclePlacement = new ConcurrentHashMap<String, String>();
public ConcurrentHashMap<String, String> preplannedVehiclePlacement = new ConcurrentHashMap<>();

/**
* Enables the plugin and activates our player listeners
Expand Down
120 changes: 87 additions & 33 deletions src/main/java/me/botsko/prism/actionlibs/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -40,10 +41,10 @@ public class ActionFactory {
* @param action_type
* @param player
*/
public static Handler createBlock(String action_type, String player) {
public static Handler createBlock(String action_type, OfflinePlayer player) {
final BlockAction a = new BlockAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
return a;
}

Expand All @@ -54,11 +55,17 @@ public static Handler createBlock(String action_type, String player) {
* @param block
* @param player
*/
public static Handler createBlock(String action_type, Block block, String player) {
public static Handler createBlock(String action_type, Block block, OfflinePlayer player) {
final BlockAction a = new BlockAction();
a.setActionType( action_type );
a.setBlock( block );
a.setPlayerName( player );
a.setPlayer( player );
return a;
}

public static Handler createBlock(String action_type, Block block, String nonPlayer) {
final Handler a = createBlock(action_type, block, (OfflinePlayer)null);
a.setNonPlayerName(nonPlayer);
return a;
}

Expand All @@ -69,11 +76,17 @@ public static Handler createBlock(String action_type, Block block, String player
* @param state
* @param player
*/
public static Handler createBlock(String action_type, BlockState state, String player) {
public static Handler createBlock(String action_type, BlockState state, OfflinePlayer player) {
final BlockAction a = new BlockAction();
a.setActionType( action_type );
a.setBlock( state );
a.setPlayerName( player );
a.setPlayer( player );
return a;
}

public static Handler createBlock(String action_type, BlockState block, String nonPlayer) {
final Handler a = createBlock(action_type, block, (OfflinePlayer)null);
a.setNonPlayerName(nonPlayer);
return a;
}

Expand All @@ -84,29 +97,36 @@ public static Handler createBlock(String action_type, BlockState state, String p
* @param player
*/
public static Handler createBlockChange(String action_type, Location loc, Material oldMat, byte oldSubid, Material newMat, byte newSubid,
String player) {
OfflinePlayer player) {
final BlockChangeAction a = new BlockChangeAction();
a.setActionType( action_type );
a.setBlock( newMat );
a.setBlockSubId( newSubid );
a.setOldBlock( oldMat );
a.setOldBlockSubId( oldSubid );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( loc );
return a;
}

public static Handler createBlockChange(String action_type, Location loc, Material oldMat, byte oldSubid, Material newMat, byte newSubid,
String nonPlayer) {
final Handler a = createBlockChange(action_type, loc, oldMat, oldSubid, newMat, newSubid, (OfflinePlayer)null);
a.setNonPlayerName(nonPlayer);
return a;
}

/**
* BlockShiftAction
*
* @param action_type
* @param player
*/
public static Handler createBlockShift(String action_type, Block from, Location to, String player) {
public static Handler createBlockShift(String action_type, Block from, Location to, String nonPlayer) {
final BlockShiftAction a = new BlockShiftAction();
a.setActionType( action_type );
a.setBlock( from );
a.setPlayerName( player );
a.setNonPlayerName( nonPlayer );
a.setToLocation( to );
return a;
}
Expand All @@ -117,17 +137,27 @@ public static Handler createBlockShift(String action_type, Block from, Location
* @param action_type
* @param player
*/
public static Handler createEntity(String action_type, Entity entity, String player) {
public static Handler createEntity(String action_type, Entity entity, OfflinePlayer player) {
return ActionFactory.createEntity(action_type, entity, player, null);
}

public static Handler createEntity(String action_type, Entity entity, String nonPlayer) {
return ActionFactory.createEntity(action_type, entity, nonPlayer, null);
}

public static Handler createEntity(String action_type, Entity entity, String player, String dyeUsed) {
public static Handler createEntity(String action_type, Entity entity, OfflinePlayer player, String dyeUsed) {
final EntityAction a = new EntityAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setEntity( entity, dyeUsed );
return a;
}

public static Handler createEntity(String action_type, Entity entity, String nonPlayer, String dyeUsed) {
final Handler a = createEntity(action_type, entity, (OfflinePlayer)null, dyeUsed);
a.setNonPlayerName(nonPlayer);
return a;
}

/**
* EntityTravelAction
Expand All @@ -150,27 +180,38 @@ public static Handler createEntityTravel(String action_type, Entity entity, Loca
* @param action_type
* @param player
*/
public static Handler createGrow(String action_type, BlockState blockstate, String player) {
public static Handler createGrow(String action_type, BlockState blockstate, OfflinePlayer player) {
final GrowAction a = new GrowAction();
a.setActionType( action_type );
a.setBlock( blockstate );
a.setPlayerName( player );
a.setPlayer( player );
return a;
}
public static Handler createGrow(String action_type, BlockState blockstate, String nonPlayer) {
final Handler a = createGrow(action_type, blockstate, (OfflinePlayer)null);
a.setNonPlayerName( nonPlayer );
return a;
}

/**
* HangingItemAction
*
* @param action_type
* @param player
*/
public static Handler createHangingItem(String action_type, Hanging hanging, String player) {
public static Handler createHangingItem(String action_type, Hanging hanging, OfflinePlayer player) {
final HangingItemAction a = new HangingItemAction();
a.setActionType( action_type );
a.setHanging( hanging );
a.setPlayerName( player );
a.setPlayer( player );
return a;
}

public static Handler createHangingItem(String action_type, Hanging hanging, String nonPlayer) {
final Handler a = createHangingItem(action_type, hanging, (OfflinePlayer)null);
a.setNonPlayerName(nonPlayer);
return a;
}

/**
* ItemStackAction
Expand All @@ -179,19 +220,26 @@ public static Handler createHangingItem(String action_type, Hanging hanging, Str
* @param player
*/
public static Handler createItemStack(String action_type, ItemStack item, Map<Enchantment, Integer> enchantments,
Location loc, String player) {
Location loc, OfflinePlayer player) {
return ActionFactory.createItemStack(action_type, item, 1, -1, enchantments, loc, player);
}

public static Handler createItemStack(String action_type, ItemStack item, int quantity, int slot,
Map<Enchantment, Integer> enchantments, Location loc, String player) {
Map<Enchantment, Integer> enchantments, Location loc, OfflinePlayer player) {
final ItemStackAction a = new ItemStackAction();
a.setActionType( action_type );
a.setLoc( loc );
a.setPlayerName( player );
a.setPlayer( player );
a.setItem( item, quantity, slot, enchantments );
return a;
}

public static Handler createItemStack(String action_type, ItemStack item, int quantity, int slot,
Map<Enchantment, Integer> enchantments, Location loc, String nonPlayer) {
final Handler a = createItemStack(action_type, item, quantity, slot, enchantments, loc, (OfflinePlayer)null);
a.setNonPlayerName(nonPlayer);
return a;
}

/**
* PlayerAction
Expand All @@ -202,7 +250,7 @@ public static Handler createItemStack(String action_type, ItemStack item, int qu
public static Handler createPlayer(String action_type, Player player, String additionalInfo) {
final PlayerAction a = new PlayerAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( player.getLocation() );
a.setData( additionalInfo );
return a;
Expand All @@ -217,7 +265,7 @@ public static Handler createPlayer(String action_type, Player player, String add
public static Handler createPlayerDeath(String action_type, Player player, String cause, String attacker) {
final PlayerDeathAction a = new PlayerDeathAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( player.getLocation() );
a.setCause( cause );
a.setAttacker( attacker );
Expand All @@ -233,7 +281,7 @@ public static Handler createPlayerDeath(String action_type, Player player, Strin
public static Handler createPrismProcess(String action_type, PrismProcessType processType, Player player, String parameters) {
final PrismProcessAction a = new PrismProcessAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( player.getLocation() );
a.setProcessData( processType, parameters );
return a;
Expand All @@ -245,11 +293,11 @@ public static Handler createPrismProcess(String action_type, PrismProcessType pr
* @param action_type
* @param player
*/
public static Handler createPrismRollback(String action_type, BlockState oldblock, BlockState newBlock, String player,
public static Handler createPrismRollback(String action_type, BlockState oldblock, BlockState newBlock, OfflinePlayer player,
int parent_id) {
final PrismRollbackAction a = new PrismRollbackAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( oldblock.getLocation() );
a.setBlockChange( oldblock, newBlock, parent_id );
return a;
Expand All @@ -262,10 +310,10 @@ public static Handler createPrismRollback(String action_type, BlockState oldbloc
* @param block
* @param player
*/
public static Handler createSign(String action_type, Block block, String[] lines, String player) {
public static Handler createSign(String action_type, Block block, String[] lines, OfflinePlayer player) {
final SignAction a = new SignAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setBlock( block, lines );
return a;
}
Expand All @@ -277,10 +325,10 @@ public static Handler createSign(String action_type, Block block, String[] lines
* @param block
* @param player
*/
public static Handler createUse(String action_type, String item_used, Block block, String player) {
public static Handler createUse(String action_type, String item_used, Block block, OfflinePlayer player) {
final UseAction a = new UseAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( block.getLocation() );
a.setData( item_used );
return a;
Expand All @@ -292,14 +340,20 @@ public static Handler createUse(String action_type, String item_used, Block bloc
* @param action_type
* @param player
*/
public static Handler createVehicle(String action_type, Vehicle vehicle, String player) {
public static Handler createVehicle(String action_type, Vehicle vehicle, OfflinePlayer player) {
final VehicleAction a = new VehicleAction();
a.setActionType( action_type );
a.setPlayerName( player );
a.setPlayer( player );
a.setLoc( vehicle.getLocation() );
a.setVehicle( vehicle );
return a;
}

public static Handler createVehicle(String action_type, Vehicle vehicle, String nonPlayer) {
final Handler a = createVehicle(action_type, vehicle, (OfflinePlayer)null);
a.setNonPlayerName( nonPlayer );
return a;
}

// Backwards compat:

Expand All @@ -317,7 +371,7 @@ public static Handler create(String action_type, Block block, String player) {
public static Handler create(String action_type, Location loc, int oldId, byte oldSubid, int newId, byte newSubid,
String player) {
return createBlockChange(action_type, loc, oldId, oldSubid, newId, newSubid, player);
}*/
}
@Deprecated
public static Handler create(String action_type, Block from, Location to, String player) {
Expand Down Expand Up @@ -404,5 +458,5 @@ public static Handler create(String action_type, String item_used, Block block,
@Deprecated
public static Handler create(String action_type, Vehicle vehicle, String player) {
return createVehicle(action_type, vehicle, player);
}
}*/
}
8 changes: 5 additions & 3 deletions src/main/java/me/botsko/prism/actionlibs/ActionsQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Map.Entry;

import org.bukkit.Material;
Expand Down Expand Up @@ -164,7 +165,7 @@ public QueryResult lookup(QueryParameters parameters, CommandSender sender) {
baseHandler.setType( actionType );
baseHandler.setId( rs.getInt( 1 ) );
baseHandler.setUnixEpoch( rs.getString( 2 ) );
baseHandler.setPlayerName( rs.getString( 4 ) );
baseHandler.setNonPlayerName( rs.getString( 4 ) );
baseHandler.setWorldName( worldName );
baseHandler.setX( rs.getInt( 6 ) );
baseHandler.setY( rs.getInt( 7 ) );
Expand Down Expand Up @@ -305,7 +306,7 @@ public PrismProcessAction getPrismProcessRecord(int id) {
ResultSet rs = null;
try {

String sql = "SELECT id, action, epoch, world, player, x, y, z, data FROM " + prefix + "data d";
String sql = "SELECT id, action, epoch, world, player, player_uuid, x, y, z, data FROM " + prefix + "data d";
// Joins
sql += " INNER JOIN " + prefix + "players p ON p.player_id = d.player_id ";
sql += " INNER JOIN " + prefix + "actions a ON a.action_id = d.action_id ";
Expand All @@ -328,7 +329,8 @@ public PrismProcessAction getPrismProcessRecord(int id) {
process.setType( Prism.getActionRegistry().getAction( rs.getString( "action" ) ) );
process.setUnixEpoch( rs.getString( "epoch" ) );
process.setWorldName( rs.getString( "world" ) );
process.setPlayerName( rs.getString( "player" ) );
process.setNonPlayerName( rs.getString( "player" ) );
process.setUUID(UUID.fromString( rs.getString("player_uuid")));
process.setX( rs.getInt( "x" ) );
process.setY( rs.getInt( "y" ) );
process.setZ( rs.getInt( "z" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static int insertActionIntoDatabase(Handler a) {
}

int player_id = 0;
// TODO: caching by name
PrismPlayer prismPlayer = PlayerIdentification.cachePrismPlayer( a.getPlayerName() );
if( prismPlayer != null ){
player_id = prismPlayer.getId();
Expand Down
Loading

0 comments on commit 4d19146

Please sign in to comment.