Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timkalkus committed Apr 26, 2021
1 parent 221097d commit f14bd3f
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 283 deletions.
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/target/classes/
/target/generated-sources/
/target/maven-archiver/
/target/maven-status/
/target/test-classes/
/target/*-snapshot.jar
#/target/classes/
#/target/generated-sources/
#/target/maven-archiver/
#/target/maven-status/
#/target/test-classes/
#/target/*-snapshot.jar
/target
/out

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
import java.util.List;
import java.util.Objects;

public class AutoReplaceListener implements Listener{
public class AutoReplaceListener implements Listener {

private final AutoReplaceMain plugin;
private static final String privateKey = "AutoReplaceKey";

public AutoReplaceListener(AutoReplaceMain plugin){
public AutoReplaceListener(AutoReplaceMain plugin) {
this.plugin = plugin;
}

@EventHandler
public void itemDamaged(PlayerItemDamageEvent event){
public void itemDamaged(PlayerItemDamageEvent event) {
if (!event.getItem().hasItemMeta())
return;
if (!(event.getItem().getItemMeta() instanceof Damageable))
Expand All @@ -36,7 +36,7 @@ public void itemDamaged(PlayerItemDamageEvent event){
ItemStack itemClone = event.getItem().clone();
Damageable tool = (Damageable) event.getItem().getItemMeta();
int itemSlot = getItemSlot(event);
if (event.getItem().getType().getMaxDurability()-tool.getDamage()<5) {
if (event.getItem().getType().getMaxDurability() - tool.getDamage() < 5) {
BukkitRunnable delayEvent = new ToolDelayEvent(event, itemClone, itemSlot);
delayEvent.runTask(plugin);
}
Expand All @@ -46,9 +46,9 @@ public void itemDamaged(PlayerItemDamageEvent event){
public void itemPlaced(PlayerInteractEvent event) {
if (!event.hasItem())
return; // ignore all event-calls without an item
if (Objects.requireNonNull(event.getItem()).getMaxStackSize()==1)
if (Objects.requireNonNull(event.getItem()).getMaxStackSize() == 1)
return; // ignore when tool, bucket or other non-stackable item
if (event.getItem().getAmount()>1)
if (event.getItem().getAmount() > 1)
return; // ignore if initital stack size is bigger than 1
if (!plugin.getPlayerItemEnabled(event.getPlayer()))
return;
Expand All @@ -58,44 +58,42 @@ public void itemPlaced(PlayerInteractEvent event) {
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if(player.hasPermission(plugin.arToolForce)) {
if (player.hasPermission(plugin.arToolForce)) {
forceTool(player);
}
if(player.hasPermission(plugin.arItemForce)){
if (player.hasPermission(plugin.arItemForce)) {
forceItem(player);
}
}

private void forceItem(Player player) {
if (player.hasPermission(plugin.arItemActivatedFalse)){
if (player.hasPermission(plugin.arItemActivatedFalse)) {
plugin.setPlayerItem(player, false);
return;
}
if (player.hasPermission(plugin.arItemActivatedTrue)){
if (player.hasPermission(plugin.arItemActivatedTrue)) {
plugin.setPlayerItem(player, true);
return;
}
plugin.setPlayerItem(player);
}

private void forceTool(Player player) {
if (player.hasPermission(plugin.arToolActivatedFalse)){
if (player.hasPermission(plugin.arToolActivatedFalse)) {
plugin.setPlayerTool(player, false);
return;
}
if (player.hasPermission(plugin.arToolActivatedTrue)){
if (player.hasPermission(plugin.arToolActivatedTrue)) {
plugin.setPlayerTool(player, true);
return;
}
plugin.setPlayerTool(player);
}



public static void markItem(ItemStack item){
public static void markItem(ItemStack item) {
ItemMeta imeta = item.getItemMeta();
List<String> lore;
assert imeta != null;
Expand All @@ -109,7 +107,7 @@ public static void markItem(ItemStack item){
item.setItemMeta(imeta);
}

public static void unmarkItem(ItemStack item){
public static void unmarkItem(ItemStack item) {
ItemMeta imeta = item.getItemMeta();
List<String> lore;
assert imeta != null;
Expand All @@ -123,14 +121,14 @@ public static void unmarkItem(ItemStack item){
item.setItemMeta(imeta);
}

private int getItemSlot(PlayerItemDamageEvent event){
private int getItemSlot(PlayerItemDamageEvent event) {
ItemStack item = event.getItem();
markItem(item);
event.getPlayer().updateInventory();
ItemStack[] inv = event.getPlayer().getInventory().getContents();
int itemSlot = -1;
for (int i = 0; i<inv.length; i++){
if (item.equals(inv[i])){
for (int i = 0; i < inv.length; i++) {
if (item.equals(inv[i])) {
itemSlot = i;
break;
}
Expand All @@ -140,14 +138,14 @@ private int getItemSlot(PlayerItemDamageEvent event){
return itemSlot;
}

private int getItemSlot(PlayerInteractEvent event){
private int getItemSlot(PlayerInteractEvent event) {
ItemStack item = event.getItem();
markItem(item);
event.getPlayer().updateInventory();
ItemStack[] inv = event.getPlayer().getInventory().getContents();
int itemSlot = -1;
for (int i = 0; i<inv.length; i++){
if (item.equals(inv[i])){
for (int i = 0; i < inv.length; i++) {
if (item.equals(inv[i])) {
itemSlot = i;
break;
}
Expand All @@ -157,15 +155,15 @@ private int getItemSlot(PlayerInteractEvent event){
return itemSlot;
}

private boolean isNullOrAir(ItemStack item) {
return item==null || isAir(item.getType());
private static boolean isNullOrAir(ItemStack item) {
return item == null || isAir(item.getType());
}

private boolean isAir(Material material){
private static boolean isAir(Material material) {
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;
}

private class ItemDelayEvent extends BukkitRunnable{
private static class ItemDelayEvent extends BukkitRunnable {

private final PlayerInteractEvent event;
private final ItemStack item; // item before
Expand All @@ -188,20 +186,20 @@ public void run() {
}
}

private class ToolDelayEvent extends BukkitRunnable{
private static class ToolDelayEvent extends BukkitRunnable {
private final PlayerItemDamageEvent event;
private final ItemStack item;
private final int itemSlot;

public ToolDelayEvent(PlayerItemDamageEvent event, ItemStack item, int itemSlot){
public ToolDelayEvent(PlayerItemDamageEvent event, ItemStack item, int itemSlot) {
this.event = event;
this.item = item;
this.itemSlot = itemSlot;
}

@Override
public void run() {
if (event.getItem().getType() != item.getType()){
if (event.getItem().getType() != item.getType()) {
ReplaceHelper rt = new ReplaceHelper(event.getPlayer(), item, itemSlot);
rt.replace();
return;
Expand Down
Loading

0 comments on commit f14bd3f

Please sign in to comment.