Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AStrangeNewUser committed Dec 2, 2018
1 parent f170b12 commit e14d7c0
Show file tree
Hide file tree
Showing 12 changed files with 718 additions and 1,041 deletions.
Binary file added dist/AutomaticInventory^3 - 1810161704.jar
Binary file not shown.
578 changes: 241 additions & 337 deletions src/me/ryanhamshire/AutomaticInventory/AIEventHandler.java

Large diffs are not rendered by default.

531 changes: 222 additions & 309 deletions src/me/ryanhamshire/AutomaticInventory/AutomaticInventory.java

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions src/me/ryanhamshire/AutomaticInventory/CustomizableMessage.java

This file was deleted.

137 changes: 51 additions & 86 deletions src/me/ryanhamshire/AutomaticInventory/DataStore.java
Original file line number Diff line number Diff line change
@@ -1,122 +1,87 @@
//Copyright 2015 Ryan Hamshire
package me.ryanhamshire.AutomaticInventory;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public class DataStore
{
//in-memory cache for messages
private String [] messages;

public class DataStore {
private final static String dataLayerFolderPath = "plugins" + File.separator + "AutomaticInventory";
final static String playerDataFolderPath = dataLayerFolderPath + File.separator + "PlayerData";
final static String messagesFilePath = dataLayerFolderPath + File.separator + "messages.yml";
private final static String messagesFilePath = dataLayerFolderPath + File.separator + "messages.yml";
//in-memory cache for messages
private HashMap<Messages, String> messages;

public DataStore()
{
public DataStore() {
//ensure data folders exist
File playerDataFolder = new File(playerDataFolderPath);
if(!playerDataFolder.exists())
{
if (!playerDataFolder.exists()) {
playerDataFolder.mkdirs();
}

this.loadMessages();
}

private void loadMessages()
{
Messages [] messageIDs = Messages.values();
this.messages = new String[Messages.values().length];

HashMap<String, CustomizableMessage> defaults = new HashMap<String, CustomizableMessage>();

}

private void loadMessages() {
Messages[] messageIDs = Messages.values();
this.messages = new HashMap<>();

//initialize defaults
//this.addDefault(defaults, Messages.NoManagedWorld, "The PopulationDensity plugin has not been properly configured. Please update your config.yml to specify a world to manage.", null);
this.addDefault(defaults, Messages.NoPermissionForFeature, "You don't have permission to use that feature.", null);
this.addDefault(defaults, Messages.ChestSortEnabled, "Now auto-sorting any chests you use.", null);
this.addDefault(defaults, Messages.ChestSortDisabled, "Stopped auto-sorting chests you use.", null);
this.addDefault(defaults, Messages.InventorySortEnabled, "Now auto-sorting your personal inventory.", null);
this.addDefault(defaults, Messages.InventorySortDisabled, "Stopped auto-sorting your personal inventory.", null);
this.addDefault(defaults, Messages.AutoSortHelp, "Options are /AutoSort Chests and /AutoSort Inventory.", null);
this.addDefault(defaults, Messages.AutoRefillEducation, "AutomaticInventory(AI) will auto-replace broken tools and depleted hotbar stacks from your inventory.", null);
this.addDefault(defaults, Messages.InventorySortEducation, "AutomaticInventory(AI) will keep your inventory sorted. Use /AutoSort to disable.", null);
this.addDefault(defaults, Messages.ChestSortEducation3, "AutomaticInventory(AI) will sort the contents of chests you access. Use /AutoSort to toggle. TIP: Want some chests sorted but not others? Chests with names including an asterisk (*) won't auto-sort. You can rename any chest using an anvil.", null);
this.addDefault(defaults, Messages.SuccessfulDeposit2, "Deposited {0} items.", null);
this.addDefault(defaults, Messages.FailedDepositNoMatch, "No items deposited - none of your inventory items match items in that chest.", null);
this.addDefault(defaults, Messages.QuickDepositAdvertisement3, "Want to deposit quickly from your hotbar? Just pick a specific chest and sneak (hold shift) while hitting it.", null);
this.addDefault(defaults, Messages.FailedDepositChestFull2, "That chest is full.", null);
this.addDefault(defaults, Messages.SuccessfulDepositAll2, "Deposited {0} items into nearby chests.", null);
this.addDefault(defaults, Messages.ChestLidBlocked, "That chest isn't accessible.", null);
this.addDefault(defaults, Messages.DepositAllAdvertisement, "TIP: Instantly deposit all items from your inventory into all the right nearby boxes with /DepositAll!", null);
//messages.put(Messages.NoManagedWorld, "The PopulationDensity plugin has not been properly configured. Please update your config.yml to specify a world to manage.");
messages.put(Messages.NoPermissionForFeature, "You don't have permission to use that feature.");
messages.put(Messages.ChestSortEnabled, "Now auto-sorting any chests you use.");
messages.put(Messages.ChestSortDisabled, "Stopped auto-sorting chests you use.");
messages.put(Messages.InventorySortEnabled, "Now auto-sorting your personal inventory.");
messages.put(Messages.InventorySortDisabled, "Stopped auto-sorting your personal inventory.");
messages.put(Messages.AutoSortHelp, "Options are /AutoSort Chests and /AutoSort Inventory.");
messages.put(Messages.AutoRefillEducation, "AutomaticInventory(AI) will auto-replace broken tools and depleted hotbar stacks from your inventory.");
messages.put(Messages.InventorySortEducation, "AutomaticInventory(AI) will keep your inventory sorted. Use /AutoSort to disable.");
messages.put(Messages.ChestSortEducation3, "AutomaticInventory(AI) will sort the contents of chests you access. Use /AutoSort to toggle. TIP: Want some chests sorted but not others? Chests with names including an asterisk (*) won't auto-sort. You can rename any chest using an anvil.");
messages.put(Messages.SuccessfulDeposit2, "Deposited {0} items.");
messages.put(Messages.FailedDepositNoMatch, "No items deposited - none of your inventory items match items in that chest.");
messages.put(Messages.QuickDepositAdvertisement3, "Want to deposit quickly from your hotbar? Just pick a specific chest and sneak (hold shift) while hitting it.");
messages.put(Messages.FailedDepositChestFull2, "That chest is full.");
messages.put(Messages.SuccessfulDepositAll2, "Deposited {0} items into nearby chests.");
messages.put(Messages.ChestLidBlocked, "That chest isn't accessible.");
messages.put(Messages.DepositAllAdvertisement, "TIP: Instantly deposit all items from your inventory into all the right nearby boxes with /DepositAll!");

//load the config file
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));
FileConfiguration outConfig = new YamlConfiguration();

//for each message ID
for(int i = 0; i < messageIDs.length; i++)
{
for (Messages messageID : messageIDs) {
//get default for this message
Messages messageID = messageIDs[i];
CustomizableMessage messageData = defaults.get(messageID.name());

//if default is missing, log an error and use some fake data for now so that the plugin can run
if(messageData == null)
{
AutomaticInventory.AddLogEntry("Missing message for " + messageID.name() + ". Please contact the developer.");
messageData = new CustomizableMessage(messageID, "Missing message! ID: " + messageID.name() + ". Please contact a server admin.", null);
}

String message = config.getString("messages." + messageID.name() + ".Text", messages.get(messageID));

//read the message from the file, use default if necessary
this.messages[messageID.ordinal()] = config.getString("Messages." + messageID.name() + ".Text", messageData.text);
outConfig.set("Messages." + messageID.name() + ".Text", this.messages[messageID.ordinal()]);

outConfig.set("messages." + messageID.name() + ".Text", message);

//support formatting codes
this.messages[messageID.ordinal()] = this.messages[messageID.ordinal()].replace('&', (char)0x00A7);

if(messageData.notes != null)
{
messageData.notes = config.getString("Messages." + messageID.name() + ".Notes", messageData.notes);
outConfig.set("Messages." + messageID.name() + ".Notes", messageData.notes);
}
messages.put(messageID, ChatColor.translateAlternateColorCodes('&', message));
}

//save any changes
try
{
try {
outConfig.options().header("Use a YAML editor like NotepadPlusPlus to edit this file. \nAfter editing, back up your changes before reloading the server in case you made a syntax error. \nUse ampersands (&) for formatting codes, which are documented here: http://minecraft.gamepedia.com/Formatting_codes");
outConfig.save(DataStore.messagesFilePath);
} catch (IOException exception) {
AutomaticInventory.logger.info("Unable to write to the configuration file at \"" + DataStore.messagesFilePath + "\"");
}
catch(IOException exception)
{
AutomaticInventory.AddLogEntry("Unable to write to the configuration file at \"" + DataStore.messagesFilePath + "\"");
}

defaults.clear();
}

private void addDefault(HashMap<String, CustomizableMessage> defaults, Messages id, String text, String notes)
{
CustomizableMessage message = new CustomizableMessage(id, text, notes);
defaults.put(id.name(), message);
}
public synchronized String getMessage(Messages messageID, String... args) {
String message = messages.get(messageID);

synchronized public String getMessage(Messages messageID, String... args)
{
String message = messages[messageID.ordinal()];

for(int i = 0; i < args.length; i++)
{
for (int i = 0; i < args.length; i++) {
String param = args[i];
message = message.replace("{" + i + "}", param);
}
return message;

return message;
}
}
7 changes: 4 additions & 3 deletions src/me/ryanhamshire/AutomaticInventory/DepositRecord.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package me.ryanhamshire.AutomaticInventory;

class DepositRecord
{
DepositRecord() {}
class DepositRecord {
int totalItems = 0;
boolean destinationFull = false;

DepositRecord() {
}
}
3 changes: 1 addition & 2 deletions src/me/ryanhamshire/AutomaticInventory/Features.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.ryanhamshire.AutomaticInventory;

enum Features
{
enum Features {
RefillStacks,
SortInventory,
SortChests,
Expand Down
Loading

0 comments on commit e14d7c0

Please sign in to comment.