Skip to content

Commit

Permalink
Fix AdminShops not being immune to natural causes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Apr 30, 2016
1 parent 1b7d58f commit 893a12d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.7c'
version = '1.8'
group = "io.github.hsyyid"
archivesBaseName = "AdminShop"

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/github/hsyyid/adminshop/AdminShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import io.github.hsyyid.adminshop.cmdexecutors.SetShopExecutor;
import io.github.hsyyid.adminshop.config.Config;
import io.github.hsyyid.adminshop.config.ShopConfig;
import io.github.hsyyid.adminshop.listeners.PlayerBreakBlockListener;
import io.github.hsyyid.adminshop.listeners.PlayerInteractBlockListener;
import io.github.hsyyid.adminshop.listeners.BreakBlockListener;
import io.github.hsyyid.adminshop.listeners.InteractBlockListener;
import io.github.hsyyid.adminshop.utils.ConfigManager;
import io.github.hsyyid.adminshop.utils.Shop;
import io.github.hsyyid.adminshop.utils.ShopModifier;
Expand All @@ -34,7 +34,7 @@
import java.util.Set;
import java.util.UUID;

@Plugin(id = "io.github.hsyyid.adminshop", name = "AdminShop", description = "This plugin adds sign shops for users to buy items.", version = "1.7c")
@Plugin(id = "io.github.hsyyid.adminshop", name = "AdminShop", description = "This plugin adds sign shops for users to buy items.", version = "1.8")
public class AdminShop
{
protected AdminShop()
Expand Down Expand Up @@ -118,8 +118,8 @@ public void init(GameInitializationEvent event)

Sponge.getCommandManager().register(this, setItemShopCommandSpec, "setshop");

Sponge.getEventManager().registerListeners(this, new PlayerBreakBlockListener());
Sponge.getEventManager().registerListeners(this, new PlayerInteractBlockListener());
Sponge.getEventManager().registerListeners(this, new BreakBlockListener());
Sponge.getEventManager().registerListeners(this, new InteractBlockListener());

getLogger().info("-----------------------------");
getLogger().info("AdminShop was made by HassanS6000!");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.hsyyid.adminshop.listeners;

import io.github.hsyyid.adminshop.AdminShop;
import io.github.hsyyid.adminshop.utils.ConfigManager;
import io.github.hsyyid.adminshop.utils.Shop;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.Optional;

public class BreakBlockListener
{
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event)
{
if (event.getCause().first(Player.class).isPresent())
{
Player player = event.getCause().first(Player.class).get();

for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
Location<World> location = transaction.getOriginal().getLocation().get();
Optional<Shop> shop = AdminShop.shops.values().stream().filter(s -> s.getSignLocation().equals(location)).findAny();

if (shop.isPresent())
{
if (player.hasPermission("adminshop.remove"))
{
AdminShop.shops.values().remove(shop.get());
ConfigManager.writeShops();
player.sendMessage(Text.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GREEN, "Shop successfully removed!"));
}
else
{
player.sendMessage(Text.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.RED, "You do not have permission to remove shops."));
event.setCancelled(true);
}
}
}
}
else
{
for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
Location<World> location = transaction.getOriginal().getLocation().get();
Optional<Shop> shop = AdminShop.shops.values().stream().filter(s -> s.getSignLocation().equals(location)).findAny();

if (shop.isPresent())
{
event.setCancelled(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Optional;
import java.util.UUID;

public class PlayerInteractBlockListener
public class InteractBlockListener
{
@Listener
public void onPlayerRightClickBlock(InteractBlockEvent.Secondary event, @First Player player)
Expand Down

This file was deleted.

0 comments on commit 893a12d

Please sign in to comment.