Skip to content

Commit

Permalink
Add reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven65 committed Jul 13, 2020
1 parent f02576f commit bd931fe
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import xyz.mackan.Slabbo.GUI.ShopDeletionGUI;
import xyz.mackan.Slabbo.Slabbo;
Expand All @@ -19,8 +20,7 @@
import xyz.mackan.Slabbo.utils.ShopUtil;

import java.io.File;
import java.util.Set;
import java.util.UUID;
import java.util.*;

@CommandAlias("slabbo")
@Description("Base command for Slabbo")
Expand All @@ -43,6 +43,46 @@ public static void onCommand(CommandSender sender, CommandHelp help) {
help.showHelp();
}

@Subcommand("reload")
@Description("Reloads Slabbo")
@CommandPermission("slabbo.reload")
public void onReload (Player player) {
player.sendMessage("Reloading Slabbo");
for (String shopKey : Slabbo.shopUtil.shops.keySet()) {
Shop shop = Slabbo.shopUtil.shops.get(shopKey);

Item droppedItem = ItemUtil.findItemEntity(shop.location);

if (droppedItem != null) {
droppedItem.remove();
}
}

Slabbo.shopUtil.shops = new HashMap<String, Shop>();
Slabbo.shopUtil.shopsByOwnerId = new HashMap<UUID, List<Shop>>();

Slabbo.shopUtil.loadShops();

for (Map.Entry<String, Shop> shopEntry : Slabbo.shopUtil.shops.entrySet()) {
String key = shopEntry.getKey();
Shop shop = shopEntry.getValue();

UUID itemUUID = UUID.randomUUID();

shop.droppedItemId = itemUUID;

Location dropLocation = shop.location.clone();

dropLocation.add(0.5, 0.5, 0.5);

ItemUtil.dropItem(dropLocation, shop.item, itemUUID);

Slabbo.shopUtil.put(key, shop);
}

player.sendMessage("Slabbo reloaded!");
}

@Subcommand("info")
@Description("Shows information about Slabbo")
@CommandPermission("slabbo.info")
Expand Down

0 comments on commit bd931fe

Please sign in to comment.