Skip to content

Commit

Permalink
Lots of change for very little difference
Browse files Browse the repository at this point in the history
  • Loading branch information
ezeiger92 committed Aug 3, 2018
1 parent 3902e9d commit 21e8875
Show file tree
Hide file tree
Showing 33 changed files with 956 additions and 964 deletions.
71 changes: 51 additions & 20 deletions src/main/java/me/botsko/prism/actionlibs/ActionFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.botsko.prism.actionlibs;

import java.util.Locale;
import java.util.Map;

import me.botsko.prism.actions.BlockAction;
Expand All @@ -24,6 +25,7 @@
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.Enchantment;
Expand All @@ -32,6 +34,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;

public class ActionFactory {
Expand Down Expand Up @@ -66,7 +69,7 @@ public static Handler createBlock(String action_type, Block block, OfflinePlayer

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

Expand All @@ -87,7 +90,7 @@ public static Handler createBlock(String action_type, BlockState state, OfflineP

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

Expand All @@ -101,9 +104,9 @@ public static Handler createBlockChange(String action_type, Location loc, Materi
Material newMat, BlockData newData, OfflinePlayer player) {
final BlockChangeAction a = new BlockChangeAction();
a.setActionType(action_type);
a.setBlock(newMat);
a.setMaterial(newMat);
a.setBlockData(newData);
a.setOldBlock(oldMat);
a.setOldMaterial(oldMat);
a.setOldBlockData(oldData);
a.setPlayer(player);
a.setLoc(loc);
Expand All @@ -113,7 +116,7 @@ public static Handler createBlockChange(String action_type, Location loc, Materi
public static Handler createBlockChange(String action_type, Location loc, Material oldMat, BlockData oldData,
Material newMat, BlockData newData, String nonPlayer) {
final Handler a = createBlockChange(action_type, loc, oldMat, oldData, newMat, newData, (OfflinePlayer) null);
a.setNonPlayerName(nonPlayer);
a.setSourceName(nonPlayer);
return a;
}

Expand All @@ -127,8 +130,8 @@ public static Handler createBlockShift(String action_type, Block from, Location
final BlockShiftAction a = new BlockShiftAction();
a.setActionType(action_type);
a.setBlock(from);
a.setNonPlayerName(nonPlayer);
a.setToLocation(to);
a.setSourceName(nonPlayer);
a.setLoc(to);
return a;
}

Expand Down Expand Up @@ -156,7 +159,7 @@ public static Handler createEntity(String action_type, Entity entity, OfflinePla

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);
a.setSourceName(nonPlayer);
return a;
}

Expand Down Expand Up @@ -192,7 +195,7 @@ public static Handler createGrow(String action_type, BlockState blockstate, Offl

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

Expand All @@ -212,7 +215,7 @@ public static Handler createHangingItem(String action_type, Hanging hanging, Off

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

Expand All @@ -229,18 +232,46 @@ public static Handler createItemStack(String action_type, ItemStack item, Map<En

public static Handler createItemStack(String action_type, ItemStack item, int quantity, int slot,
Map<Enchantment, Integer> enchantments, Location loc, OfflinePlayer player) {
final ItemStackAction a = createItemStack(action_type, item, quantity, enchantments, loc, player);
a.setSlot(String.valueOf(slot));

return a;
}

public static Handler createItemStack(String action_type, ItemStack item, int quantity, BlockFace slot,
Map<Enchantment, Integer> enchantments, Location loc, OfflinePlayer player) {
final ItemStackAction a = createItemStack(action_type, item, quantity, enchantments, loc, player);
a.setSlot(slot.name().toLowerCase(Locale.ENGLISH));

return a;
}

public static Handler createItemStack(String action_type, ItemStack item, int quantity, int slot,
Map<Enchantment, Integer> enchantments, Location loc, String sourceName) {
final ItemStackAction a = new ItemStackAction();
a.setActionType(action_type);
a.setLoc(loc);
a.setPlayer(player);
a.setItem(item, quantity, slot, enchantments);
a.setSourceName(sourceName);
a.setItem(item, quantity, enchantments);
a.setSlot(String.valueOf(slot));
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);
public static Handler createItemStack(String action_type, ItemStack item, int quantity, EquipmentSlot slot,
Map<Enchantment, Integer> enchantments, Location loc, OfflinePlayer player) {
final ItemStackAction a = createItemStack(action_type, item, quantity, enchantments, loc, player);
a.setSlot(slot.name().toLowerCase(Locale.ENGLISH));

return a;
}

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

Expand All @@ -255,7 +286,7 @@ public static Handler createPlayer(String action_type, Player player, String add
a.setActionType(action_type);
a.setPlayer(player);
a.setLoc(player.getLocation());
a.setData(additionalInfo);
a.deserialize(additionalInfo);
return a;
}

Expand Down Expand Up @@ -329,12 +360,12 @@ 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, OfflinePlayer player) {
public static Handler createUse(String action_type, Material item, Block block, OfflinePlayer player) {
final UseAction a = new UseAction();
a.setActionType(action_type);
a.setPlayer(player);
a.setLoc(block.getLocation());
a.setData(item_used);
a.setMaterial(item);
return a;
}

Expand All @@ -355,7 +386,7 @@ public static Handler createVehicle(String action_type, Vehicle vehicle, Offline

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

Expand Down
45 changes: 25 additions & 20 deletions src/main/java/me/botsko/prism/actionlibs/ActionMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.botsko.prism.utils.BlockUtils;

import org.bukkit.ChatColor;
import org.bukkit.Location;

public class ActionMessage {

Expand Down Expand Up @@ -55,26 +56,28 @@ public void setResultIndex(int index) {
*/
public String getRawMessage() {
final StringBuilder msg = new StringBuilder();
msg.append((a.getType().doesCreateBlock() || a.getType().getName().equals("item-insert")
|| a.getType().getName().equals("sign-change")) ? "+" : "-");
ActionType action = a.getActionType();

msg.append((action.doesCreateBlock() || action.getName().equals("item-insert")
|| action.getName().equals("sign-change")) ? "+" : "-");
msg.append(" #" + a.getId());
msg.append(" " + a.getPlayerName());
msg.append(" " + a.getType().getName());
msg.append(" " + a.getBlock());
msg.append(" " + a.getSourceName());
msg.append(" " + action.getName());
msg.append(" " + a.getMaterial());
msg.append(BlockUtils.dataString(a.getBlockData()));

if (a.getType().getHandler() != null) {
if (action.getHandler() != null) {
if (!a.getNiceName().isEmpty())
msg.append(" (" + a.getNiceName() + ")");
}
else {
// We should really improve this, but this saves me from having to
// make
// a custom handler.
if (a.getType().getName().equals("lava-bucket")) {
if (action.getName().equals("lava-bucket")) {
msg.append(" (lava)");
}
else if (a.getType().getName().equals("water-bucket")) {
else if (action.getName().equals("water-bucket")) {
msg.append(" (water)");
}
}
Expand All @@ -83,7 +86,8 @@ else if (a.getType().getName().equals("water-bucket")) {
}
msg.append(" " + a.getDisplayDate());
msg.append(" " + a.getDisplayTime().toLowerCase());
msg.append(" - " + a.getWorldName() + " @ " + a.getX() + " " + a.getY() + " " + a.getZ());
Location l = a.getLoc();
msg.append(" - " + l.getWorld().getName() + " @ " + l.getBlockX() + " " + l.getBlockY() + " " + l.getBlockZ());
return msg.toString();
}

Expand All @@ -110,33 +114,34 @@ public String[] getMessage() {
}

// Who
line1 += highlight + a.getPlayerName();
line1 += highlight + a.getSourceName();

String description = a.getCustomDesc();
ActionType action = a.getActionType();

if (description == null)
description = a.getType().getNiceDescription();
description = action.getNiceDescription();

// Description of event
line1 += " " + ChatColor.WHITE + description;
if (a.getType().getHandler() != null) {
if (action.getHandler() != null) {
if (!a.getNiceName().isEmpty())
line1 += " " + highlight + a.getNiceName();
}
else {
// We should really improve this, but this saves me from having to
// make
// a custom handler.
if (a.getType().getName().equals("lava-bucket")) {
if (action.getName().equals("lava-bucket")) {
line1 += " " + highlight + "lava";
}
else if (a.getType().getName().equals("water-bucket")) {
else if (action.getName().equals("water-bucket")) {
line1 += " " + highlight + "water";
}
}

if (showExtended) {
line1 += " " + a.getBlock() + a.getBlockData();
line1 += " " + a.getMaterial() + a.getBlockData();
}

// Aggregate count
Expand All @@ -150,7 +155,7 @@ else if (a.getType().getName().equals("water-bucket")) {
}

// Action type reminder
line1 += " " + ChatColor.GRAY + "(a:" + a.getType().getShortName() + ")";
line1 += " " + ChatColor.GRAY + "(a:" + action.getShortName() + ")";

// Line 2
String line2 = ChatColor.GRAY + " --";
Expand All @@ -161,8 +166,8 @@ else if (a.getType().getName().equals("water-bucket")) {
if (showExtended) {
line2 += ChatColor.GRAY + a.getDisplayDate();
line2 += " " + ChatColor.GRAY + a.getDisplayTime().toLowerCase();

line2 += " - " + a.getWorldName() + " @ " + a.getX() + " " + a.getY() + " " + a.getZ() + " ";
Location l = a.getLoc();
line2 += " - " + l.getWorld().getName() + " @ " + l.getBlockX() + " " + l.getBlockY() + " " + l.getBlockZ() + " ";
}

msg[0] = line1;
Expand All @@ -180,8 +185,8 @@ else if (a.getType().getName().equals("water-bucket")) {
*/
protected String getPosNegPrefix() {

if (a.getType().doesCreateBlock() || a.getType().getName().equals("item-insert")
|| a.getType().getName().equals("sign-change")) {
if (a.getActionType().doesCreateBlock() || a.getActionType().getName().equals("item-insert")
|| a.getActionType().getName().equals("sign-change")) {
return ChatColor.GREEN + " + " + ChatColor.WHITE;
}
else {
Expand Down
Loading

0 comments on commit 21e8875

Please sign in to comment.