Skip to content

Commit

Permalink
* Implemented the "killCurrentShopPacket" method in the DisplayShopsA…
Browse files Browse the repository at this point in the history
…PI interface to allow more control over visual updates when changing a shops data that needs to effect to the shops appearance in the moment.

* Implemented the “getLastBuyTimeStamp” and “getLastSellTimeStamp” in the Shop interface for the new dynamic price changing system. In addition, their setters were implemented as well.
* Implemented the "isReadyForDynamicReset" method inside the the Shop interface. This method will be used for date comparison using time stamps for both buy and sell transactions if dynamic price changing is enabled for the shop.
* In addition to the removal of “syncBaseBlocks”, this also removed the task id getters and setters alongside the chunk coords map.
* Added the “isPaperSpigot”, "getLoggingFile", and "writeToLog" methods to the main class for easy determination for developers.
* The "buildShopEditMenu" method found in the Manager interface now returns an Inventory object alongside requires a Player parameter.
* Removed access to all tasks aside the ID values. These are more internal and intended to be protected. Methods required to modify things directly in these tasks can be found in the Main class (DisplayShopsAPI or DisplayShops depending on if the API JAR is used as the dependency).
* The “getBaseMaterial” method found in the API’s Manager interface has been swapped to return a String instead of the Material type. This allows a single line of information containing <material>:<durability>.
* The “getInitialBaseBlockMaterial” and “setInitialBaseBlockMaterial” were completely replaced with the “getStoredBaseBlockMaterial” and “setStoredBaseBlockMaterial" methods.
* The "getStoredBalance" and "setStoredBalance" methods were implemented to support the new currency handling system.
* Removed the "getPhysicalCurrencyStock" and "setPhysicalCurrencyStock" methods from the Shop interface due to the currency handling changes.
* Removed the “syncBaseBlocks” method from the main class. This method was synchronous and doesn’t handle anything but set the stored materials to shops that have no base block material.
* Removed many player-data related method such as the chat interaction map, chat tasks, cooldowns, etc. from the Manager interface. Instead each player is now given a DataPack object which stores this information and load/unloads based on online status.

Signed-off-by: BuildTools <[email protected]>
  • Loading branch information
BuildTools committed May 18, 2020
1 parent 2b03648 commit ef783ba
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 104 deletions.
2 changes: 1 addition & 1 deletion API Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## API-VERSION 1.0.2 ##
## API-VERSION 1.0.4 ##
42 changes: 19 additions & 23 deletions src/xzot1k/plugins/ds/DisplayShops.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xzot1k.plugins.ds.api.handlers.DisplayPacket;
import xzot1k.plugins.ds.api.objects.Shop;

import java.io.File;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -49,11 +50,6 @@ public void setupTasks() {

}

@Override
public void syncBaseBlocks() {

}

@Override
public String getLatestVersion() {
return null;
Expand Down Expand Up @@ -84,6 +80,11 @@ public DisplayPacket getDisplayPacket(Shop shop, Player player) {
return null;
}

@Override
public void killCurrentShopPacket(Player player) {

}

@Override
public void clearDisplayPackets(Player player) {

Expand Down Expand Up @@ -125,13 +126,13 @@ public String getServerVersion() {
}

@Override
public boolean isOffHandVersion() {
public boolean isPaperSpigot() {
return false;
}

@Override
public HashMap<UUID, UUID> getShopMemory() {
return null;
public boolean isOffHandVersion() {
return false;
}

@Override
Expand All @@ -140,22 +141,12 @@ public Connection getDatabaseConnection() {
}

@Override
public int getAutoSaveTaskId() {
return 0;
}

@Override
public void setAutoSaveTaskId(int autoSaveTaskId) {

}

@Override
public int getShopSyncTaskId() {
public int getManagementTaskId() {
return 0;
}

@Override
public void setShopSyncTaskId(int shopSyncTaskId) {
public void setManagementTaskId(int managementTaskId) {

}

Expand All @@ -170,17 +161,22 @@ public void setInSightTask(int inSightTask) {
}

@Override
public HashMap<UUID, String> getChunkCoordMap() {
public List<UUID> getTeleportingPlayers() {
return null;
}

@Override
public List<UUID> getPacketReceivedDelayedPlayers() {
public HashMap<UUID, UUID> getShopMemory() {
return null;
}

@Override
public List<UUID> getTeleportingPlayers() {
public File getLoggingFile() {
return null;
}

@Override
public void writeToLog(String text) {

}
}
50 changes: 34 additions & 16 deletions src/xzot1k/plugins/ds/DisplayShopsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xzot1k.plugins.ds.api.handlers.DisplayPacket;
import xzot1k.plugins.ds.api.objects.Shop;

import java.io.File;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
Expand All @@ -32,11 +33,6 @@ interface DisplayShopsAPI {
*/
void setupTasks();

/**
* Syncs all block materials to their defined shops.
*/
void syncBaseBlocks();

/**
* Gets latest version text from Spigot.
*
Expand Down Expand Up @@ -81,8 +77,17 @@ interface DisplayShopsAPI {
*/
DisplayPacket getDisplayPacket(Shop shop, Player player);

/**
* Kills the current shop packets in view and removes it from memory for the player.
* (Note: This is ONLY used for the shop the player is currently looking at)
*
* @param player The player to kill the packet for.
*/
void killCurrentShopPacket(Player player);

/**
* Clears all display packets for a player on file.
* (Note: Does NOT kill packet displays. Use the kill method found in the shop interface.)
*
* @param player The player to remove the packets for.
*/
Expand Down Expand Up @@ -149,28 +154,41 @@ interface DisplayShopsAPI {
*/
String getServerVersion();

boolean isOffHandVersion();
/**
* Checks if paper spigot methods exist.
*
* @return Whether paper spigot is detected.
*/
boolean isPaperSpigot();

HashMap<UUID, UUID> getShopMemory();
/**
* This gets the logging file.
*
* @return The file used for plugin logging.
*/
File getLoggingFile();

Connection getDatabaseConnection();
/**
* Writes to the log file if size does NOT exceed configuration limitations.
*
* @param text The text to store on the next available line in the file.
*/
void writeToLog(String text);

int getAutoSaveTaskId();
boolean isOffHandVersion();

void setAutoSaveTaskId(int autoSaveTaskId);
Connection getDatabaseConnection();

int getShopSyncTaskId();
int getManagementTaskId();

void setShopSyncTaskId(int shopSyncTaskId);
void setManagementTaskId(int managementTaskId);

int getInSightTask();

void setInSightTask(int inSightTask);

HashMap<UUID, String> getChunkCoordMap();

List<UUID> getPacketReceivedDelayedPlayers();

List<UUID> getTeleportingPlayers();

HashMap<UUID, UUID> getShopMemory();

}
105 changes: 51 additions & 54 deletions src/xzot1k/plugins/ds/api/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,32 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionType;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import xzot1k.plugins.ds.api.enums.ChatInteractionType;
import xzot1k.plugins.ds.api.events.EconomyCallEvent;
import xzot1k.plugins.ds.api.events.EconomyCallType;
import xzot1k.plugins.ds.api.handlers.ActionBarHandler;
import xzot1k.plugins.ds.api.handlers.JItemHandler;
import xzot1k.plugins.ds.api.handlers.ParticleHandler;
import xzot1k.plugins.ds.api.objects.DataPack;
import xzot1k.plugins.ds.api.objects.MarketRegion;
import xzot1k.plugins.ds.api.objects.Region;
import xzot1k.plugins.ds.api.objects.Shop;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public interface Manager {

/**
* Loads the passed player's data pack. If not found, a new data pack module is created.
*
* @param player The player to load the data pack for.
*/
CompletableFuture<DataPack> loadDataPack(Player player);

/**
* Ray traces from the provided vectors to obtain a shop from the locations it passes through.
*
Expand Down Expand Up @@ -63,6 +70,14 @@ public interface Manager {
*/
void initiateChatInteractionOperation(Player player, ChatInteractionType chatInteractionType, String playerEntryValue);

/**
* Sends a color translated message to the players as either a normal chat message or action bar message.
*
* @param player The player to send the message to.
* @param message The message to send (color codes accepted, if the message contains {bar} at the front it will be sent to the action bar).
*/
void sendMessage(Player player, String message);

/**
* Gives itemstack to player 'X' amount of times at a specific unit count (stack count)
*
Expand All @@ -73,34 +88,6 @@ public interface Manager {
*/
void giveItem(Player player, ItemStack itemStack, int amount, int unitCount);

/**
* Updates the cooldown id for the passed player.
*
* @param player The player to update the cooldown for.
* @param cooldownId The cooldown id to update.
*/
void updateCooldown(Player player, String cooldownId);

/**
* Checks if the passed player has a cooldown at the specified id based on the base cooldown value.
*
* @param player The player to check.
* @param cooldownId The cooldown id.
* @param cooldown The cooldown's amount (normally the configuration value).
* @return Whether the cooldown is active (above zero).
*/
boolean isOnCooldown(Player player, String cooldownId, int cooldown);

/**
* Gets the cooldown left for the player at a specified id.
*
* @param player The player to get the cooldown from.
* @param cooldownId The cooldown id.
* @param cooldown The cooldown value (Usually from configuration).
* @return The cooldown time remaining.
*/
long getCooldown(Player player, String cooldownId, int cooldown);

/**
* Retrieve a market region, if the passed location is inside it.
*
Expand Down Expand Up @@ -262,12 +249,20 @@ public interface Manager {
void loadMarketRegions();

/**
* This method grabs the first permission based base-block material the player can have for a shop.
* Obtains the default base material without checking attached durability.
*
* @return The material type.
*/
Material getBaseBlockType();

/**
* This method goes through the player's permissions and checks if they have access to the material.
*
* @param player The player to check permissions of.
* @return The found material with a backup default of CHEST.
* @param player The player to check permissions of.
* @param materialLine The material name or the format <material>:<durability> to check for.
* @return if they have access.
*/
Material getBaseBlockMaterial(Player player);
boolean hasAccessToBaseBlock(Player player, String materialLine);

/**
* Returns a list of all shops owned by the player.
Expand All @@ -285,6 +280,14 @@ public interface Manager {
*/
boolean exceededShopLimit(Player player);

/**
* Gets the player specific shop promotion item modifier.
*
* @param player The player to check.
* @return The modifier for multiplication.
*/
double getPromotionPriceModifier(Player player);

/**
* Gives the passed item stack to the player the passed amount of times in the form of stacks.
*
Expand Down Expand Up @@ -356,10 +359,22 @@ public interface Manager {
*/
ItemStack buildShopCurrencyItem(int amount);

/**
* Gets the base-block selection GUI and calculates the player's access, current shop base-block, etc.
*
* @param player The player to use for permission basing.
* @param shop The shop to use to get information from.
* @return The complete GUI.
*/
Inventory getBaseBlockSelectionMenu(Player player, Shop shop);

/**
* Builds and sets the shop edit menu from the configuration to the variable.
*
* @param player The player the edit menu needs to be built for.
* @return The built inventory.
*/
void buildShopEditMenu();
Inventory buildShopEditMenu(Player player);

/**
* Builds and sets the shop transaction menu from the configuration to the variable.
Expand All @@ -382,36 +397,18 @@ public interface Manager {
*/
boolean isBlockedWorld(World world);

/**
* Updates player's personal chat task values.
*
* @param player The player to update.
*/
void updatePersonalChatTask(Player player);

// getters & setters
HashMap<UUID, Shop> getShopMap();

HashMap<UUID, Shop> getShopInteractionMap();

HashMap<UUID, String> getChatInteractionMap();

ParticleHandler getParticleHandler();

JItemHandler getJItemHandler();

ActionBarHandler getActionBarHandler();

Inventory getShopEditMenu();

List<MarketRegion> getMarketRegions();

HashMap<UUID, Region> getRegionSelectionMap();

List<UUID> getSelectionModePlayers();

SimpleDateFormat getDateFormat();

HashMap<UUID, BukkitTask> getPersonalChatTasks();

HashMap<UUID, DataPack> getDataPackMap();
}
3 changes: 2 additions & 1 deletion src/xzot1k/plugins/ds/api/enums/ChatInteractionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

public enum ChatInteractionType {
SHOP_ITEM_AMOUNT("change-item-amount"), BUY_LIMIT("buy-limit"), SELL_LIMIT("sell-limit"), BUY_PRICE("change-buy-price"),
SELL_PRICE("change-sell-price"), WITHDRAW_STOCK("withdraw-stock"), DEPOSIT_STOCK("deposit-stock"), EDIT_DESCRIPTION("edit-description");
SELL_PRICE("change-sell-price"), WITHDRAW_STOCK("withdraw-stock"), DEPOSIT_STOCK("deposit-stock"), EDIT_DESCRIPTION("edit-description"),
DEPOSIT_BALANCE("deposit-balance"), WITHDRAW_BALANCE("withdraw-balance");

String interactionId;

Expand Down
Loading

0 comments on commit ef783ba

Please sign in to comment.