Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random stuff #185

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@ currency value and money transactions are based on actual items in Minecraft, pe
a greater level of immersion, a generally more Minecraft-like feeling, and in the case of a PvP environment, making the
currency itself vulnerable to raiding.


### ⚠ Breaking Changes in Version 3.0.0

This version changed the way data are stored, so if you come from an older version of Gringotts, you need to manually update your database.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: way data are stored --> data is stored.


- Shutdown your server
- In your plugins folder, open the folder named `Gringotts`
- Make a copy of the file `Gringotts.db` in case something goes wrong during the update.
- Install sqlite3 command-line program, on linux you can do so by entering the following in the terminal `sudo apt install sqlite3`
(for windows refer to [this link](https://www.sqlite.org/cli.html))
- Open your terminal in Gringotts' directory and enter this command `sqlite3 Gringotts.db`
- In the shell enter the following instructions
```
CREATE TABLE db_migration (
id integer not null,
mchecksum integer not null,
mtype varchar(1) not null,
mversion varchar(150) not null,
mcomment varchar(150) not null,
mstatus varchar(10) not null,
run_on timestamp not null,
run_by varchar(30) not null,
run_time integer not null,
constraint pk_db_migration primary key (id)
);
```
Execute and then enter
`INSERT INTO db_migration VALUES(0,0,'I','0','<init>','SUCCESS',1721777343415,'foo',0);`
and
`INSERT INTO db_migration VALUES(1,-1450547331,'V','1.0','initial','SUCCESS',1721777343415,'foo',1);`

- If everything went smoothly you should be done, exit sqlite by typing `.exit`, replace gringotts.jar by the new version and start your server.

> You may get the error `Error: attempt to write a readonly database`, that means that your user doesn't have write permission for the file Gringotts.db.

> On the first launch you will get lot of `Balance differs for account` errors, they can be ignored. If you get one after that, please open an issue as it may indicate a money duplication glitch.


### Get Gringotts

- [from Spigot](https://www.spigotmc.org/resources/gringotts.42071/)
Expand Down
6 changes: 3 additions & 3 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jdk:
- openjdk17
- openjdk21
before_install:
- sdk install java 17.0.3-open
- sdk use java 17.0.3-open
- sdk install java 21.0.4-open
- sdk use java 21.0.4-open
- sdk install maven
- mvn -v
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<properties>
<maven.deploy.skip>false</maven.deploy.skip>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -130,7 +130,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.2</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gestern/gringotts/Gringotts.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Gringotts() {
}

public String getVersion() {
return getDescription().getVersion();
return getPluginMeta().getVersion();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.gestern.gringotts.accountholder;


import java.util.Set;
import java.util.UUID;

import org.bukkit.OfflinePlayer;
import org.gestern.gringotts.event.VaultCreationEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;
import java.util.UUID;

/**
* Provides AccountHolder objects for a given id.
* An AccountHolderProvider has its own internal mapping of ids to account holders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default String getName() {
*/
default String getVersion() {
return this.getPlugin()
.getDescription()
.getPluginMeta()
.getVersion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Set<String> getBanks() {
*/
@Override
public Account getAccount(String id) {
String[] parts = id.split(":");
String[] parts = id.split("-", 2);

if (parts.length == 1) {
OfflinePlayer player = Util.getOfflinePlayer(id);
Expand Down
38 changes: 6 additions & 32 deletions src/main/java/org/gestern/gringotts/api/impl/VaultConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ public String currencyNameSingular() {

@Override
public boolean hasAccount(String accountId) {
OfflinePlayer player = Util.getOfflinePlayer(accountId);

if (player != null) {
return hasAccount(player);
}

return eco.account(accountId).exists();
return eco.getAccount(accountId).exists();
}

@Override
Expand All @@ -75,14 +69,8 @@ public boolean hasAccount(OfflinePlayer offlinePlayer) {
}

@Override
public double getBalance(String accountId) {
OfflinePlayer player = Util.getOfflinePlayer(accountId);

if (player != null) {
return getBalance(player);
}

return eco.account(accountId).balance();
public double getBalance(String accountId) { // TODO optimize
return eco.getAccount(accountId).balance();
}

@Override
Expand All @@ -92,13 +80,7 @@ public double getBalance(OfflinePlayer offlinePlayer) {

@Override
public boolean has(String accountId, double amount) {
OfflinePlayer player = Util.getOfflinePlayer(accountId);

if (player != null) {
return has(player, amount);
}

return eco.account(accountId).has(amount);
return eco.getAccount(accountId).has(amount);
}

@Override
Expand All @@ -108,15 +90,7 @@ public boolean has(OfflinePlayer offlinePlayer, double amount) {

@Override
public EconomyResponse withdrawPlayer(String accountId, double amount) {
OfflinePlayer player = Util.getOfflinePlayer(accountId);

if (player != null) {
return withdrawPlayer(player, amount);
}

Account account = eco.account(accountId);

return withdrawPlayer(account, amount);
return withdrawPlayer(eco.getAccount(accountId), amount);
}

@Override
Expand All @@ -142,7 +116,7 @@ private EconomyResponse withdrawPlayer(Account account, double amount) {

@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
Account account = eco.account(playerName);
Account account = eco.getAccount(playerName);
return depositPlayer(account, amount);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.gestern.gringotts.currency;

import java.util.Objects;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.gestern.gringotts.Configuration;

import java.util.HashMap;
import java.util.Objects;

/**
* Hashable information to identify a denomination by it's ItemStack.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gestern/gringotts/data/EBeanDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public boolean renameAccount(String type, String oldName, String newName) {
@Override
public synchronized List<AccountChest> retrieveChests(GringottsAccount account) {
if (!allChests.isEmpty()) {
return allChests.stream().filter(ac -> ac.account.owner.equals(account.owner)).collect(Collectors.toList());
return allChests.stream().filter(ac -> ac.account.owner.getId().equals(account.owner.getId())).collect(Collectors.toList());
}
SqlQuery getChests = db.sqlQuery("SELECT ac.world, ac.x, ac.y, ac.z, ac.total_value " +
"FROM gringotts_accountchest ac JOIN gringotts_account a ON ac.account = a.id " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.gestern.gringotts.dependency;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.gestern.gringotts.Gringotts;
import org.gestern.gringotts.Util;
import org.gestern.gringotts.api.dependency.Dependency;
import org.gestern.gringotts.api.dependency.DependencyProvider;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* The type Dependency provider.
*/
Expand Down Expand Up @@ -52,8 +51,7 @@ public Plugin hookPlugin(String name, String classpath, String minVersion) {
"Plugin %s hooked.", name
));

PluginDescriptionFile desc = plugin.getDescription();
String version = desc.getVersion();
String version = plugin.getPluginMeta().getVersion();

if (!Util.versionAtLeast(version, minVersion)) {
this.gringotts.getLogger().warning(String.format(
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/gestern/gringotts/event/AccountListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
Expand All @@ -21,6 +22,8 @@

import com.destroystokyo.paper.event.block.BlockDestroyEvent;

import io.papermc.paper.event.player.PlayerOpenSignEvent;

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -132,6 +135,33 @@ public void run() {
}
}

@EventHandler
public void onDispenseEvent(BlockDispenseEvent event) {
if (event.getBlock().getState() instanceof InventoryHolder) {
AccountChest chest = getAccountChestFromHolder((InventoryHolder) event.getBlock().getState());
if (chest != null) {
new BukkitRunnable() {
@Override
public void run() {
chest.setCachedBalance(chest.balance(true));
Gringotts.instance.getDao().updateChestBalance(chest, chest.getCachedBalance());
}
}.runTask(Gringotts.instance);
}
}
}

@EventHandler
public void onSignEdit(PlayerOpenSignEvent event) {
for (AccountChest chest : Gringotts.instance.getDao().retrieveChests()) {
if (!chest.isChestLoaded()) continue; // For a sign to be changed, it needs to be loaded
if (event.getSign().equals(chest.sign)) {
event.setCancelled(true);
return;
}
}
}

/**
* Get the AccountChest associated with this {@link InventoryHolder}
* @param holder
Expand Down
Loading