Skip to content

Commit 691f4fb

Browse files
committed
Plugin rewrite #20
1 parent acbc208 commit 691f4fb

28 files changed

+392
-371
lines changed

config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ messages:
2727
mine_regen_all: '&7All mines have been regenerated.'
2828
permission_denied: '&cPermission denied.'
2929
must_be_player: '&cYou must be a player to excecute this command.'
30-
could_not_save_economy: '&cCould not save economy.'
31-
could_not_save_tickets: '&cCould not save tickets.'
32-
economy_saved: '&7Economy was saved to a file.'
33-
tickets_saved: '&7Tickets were saved to a file'
3430
reload_complete: '&7Reload complete.'
3531
seller_received: '&7You received a seller chest.'
3632
can_not_do_that_here: '&7You can not do that here!'

plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: AntaresPrison
2-
version: 1.4
2+
version: 1.5
33
api-version: 1.15
44
depend: [PlaceholderAPI, Multiverse-Core]
55
authors: [piotrwyrw, nathen418]
6-
description: Special thanks to the whole Antares community for helping to test and improve this plugin.
6+
description: Thanks to the whole Antares community for helping to develop this plugin!
77
load: POSTWORLD
88
main: org.piotrwyrw.antares.prison.AntaresPrison
99
commands:

src/org/piotrwyrw/antares/prison/AntaresPrison.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.World;
5+
import org.bukkit.entity.Player;
56
import org.bukkit.event.HandlerList;
67
import org.bukkit.plugin.java.JavaPlugin;
7-
import org.bukkit.scheduler.BukkitRunnable;
88
import org.piotrwyrw.antares.prison.commands.PrisonCommand;
99
import org.piotrwyrw.antares.prison.constants.MessageConstants;
1010
import org.piotrwyrw.antares.prison.events.*;
1111
import org.piotrwyrw.antares.prison.objects.MineAutoRegen;
12+
import org.piotrwyrw.antares.prison.utils.ListUtil;
1213
import org.piotrwyrw.antares.prison.utils.MessageSender;
1314

1415
public class AntaresPrison extends JavaPlugin {
1516

1617
static AntaresPrison antaresPrison;
1718
public Mines mines;
18-
public Economy economy;
1919
public WorthManager worthManager;
2020
public World world;
2121
public MineAutoRegen autoRegen;
2222
public Rooms rooms;
23-
public Tickets tickets;
2423
public Configuration config;
25-
public Temporary temporary;
2624
public MessageSender msd;
25+
public PrisonsUsers users;
2726

2827
private boolean checkPlaceholderAPI() {
2928
if (!getServer().getPluginManager().getPlugin("PlaceholderAPI").isEnabled()) {
@@ -63,25 +62,23 @@ public void onEnable() {
6362

6463
MessageConstants.updatePluginSummary();
6564

65+
66+
users = new PrisonsUsers("users.yml");
67+
users.loadFromFile();
6668
mines = new Mines("mines.yml");
67-
economy = new Economy("economy.yml");
6869
worthManager = new WorthManager("worth.yml");
6970
rooms = new Rooms("rooms.yml");
70-
tickets = new Tickets("tickets.yml");
7171
autoRegen = new MineAutoRegen();
7272
config = new Configuration("config.yml");
73-
temporary = new Temporary();
7473

7574
if (!config.loadFromFile())
7675
return;
7776

7877
this.world = config.world;
7978

8079
mines.loadFromFile();
81-
economy.loadFromFile();
8280
worthManager.loadFromFile();
8381
rooms.loadFromFile();
84-
tickets.loadFromFile();
8582

8683
mines.regenAllMines();
8784

@@ -93,6 +90,12 @@ public void onEnable() {
9390
registerCommands();
9491
registerEvents();
9592

93+
for (Player p : Bukkit.getOnlinePlayers()) {
94+
if (users.getUser(p) != null)
95+
continue;
96+
users.addUser(new PrisonsUser(p.getUniqueId(), ListUtil.empty(), 0.0d));
97+
}
98+
9699
}
97100

98101
private void registerEvents() {
@@ -124,17 +127,14 @@ private void registerCommands() {
124127
public void onDisable() {
125128
HandlerList.unregisterAll(this);
126129
msd.toAllAdmins(MessageConstants.PLUGIN_DISABLE, true);
130+
users.saveToFile();
127131
Bukkit.getScheduler().cancelTasks(this);
128-
economy.saveToFile();
129-
tickets.saveToFile();
132+
users = null;
130133
mines = null;
131134
worthManager = null;
132-
economy = null;
133135
rooms = null;
134136
autoRegen = null;
135137
world = null;
136-
tickets = null;
137-
temporary = null;
138138
config = null;
139139
msd = null;
140140
}

src/org/piotrwyrw/antares/prison/Configuration.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.piotrwyrw.antares.prison;
22

3-
import com.mojang.brigadier.Message;
43
import org.bukkit.Bukkit;
54
import org.bukkit.World;
65
import org.bukkit.configuration.file.FileConfiguration;
@@ -77,10 +76,6 @@ public boolean loadFromFile() {
7776
MessageConstants.MINE_REGEN_ALL = safeLoad("messages.mine_regen_all", MessageConstants.MINE_REGEN_ALL);
7877
MessageConstants.PERMISSION_DENIED = safeLoad("messages.permission_denied", MessageConstants.PERMISSION_DENIED);
7978
MessageConstants.MUST_BE_PLAYER = safeLoad("messages.must_be_player", MessageConstants.MUST_BE_PLAYER);
80-
MessageConstants.COULD_NOT_SAVE_ECONOMY = safeLoad("messages.could_not_save_economy", MessageConstants.COULD_NOT_SAVE_ECONOMY);
81-
MessageConstants.COULD_NOT_SAVE_TICKETS = safeLoad("messages.could_not_save_tickets", MessageConstants.COULD_NOT_SAVE_TICKETS);
82-
MessageConstants.ECONOMY_SAVED = safeLoad("messages.economy_saved", MessageConstants.ECONOMY_SAVED);
83-
MessageConstants.TICKETS_SAVED = safeLoad("messages.tickets_saved", MessageConstants.TICKETS_SAVED);
8479
MessageConstants.RELOAD_COMPLETE = safeLoad("messages.reload_complete", MessageConstants.RELOAD_COMPLETE);
8580
MessageConstants.SELLER_RECEIVED = safeLoad("messages.seller_received", MessageConstants.SELLER_RECEIVED);
8681
MessageConstants.CANT_DO_THAT_HERE = safeLoad("messages.can_not_do_that_here", MessageConstants.CANT_DO_THAT_HERE);

src/org/piotrwyrw/antares/prison/Economy.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/org/piotrwyrw/antares/prison/Mines.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.piotrwyrw.antares.prison.constants.MessageConstants;
99
import org.piotrwyrw.antares.prison.objects.Area;
1010
import org.piotrwyrw.antares.prison.objects.Mine;
11-
import org.piotrwyrw.antares.prison.utils.MessageSender;
1211

1312
import java.io.File;
1413
import java.io.IOException;

src/org/piotrwyrw/antares/prison/PrisonPlaceHolders.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ public String getVersion() {
2323

2424
@Override
2525
public String onPlaceholderRequest(Player p, String identifier) {
26+
PrisonsUsers users = AntaresPrison.getInstance().users;
27+
PrisonsUser user = users.getUser(p);
2628
if (identifier.equalsIgnoreCase("balance")) {
27-
double bal = AntaresPrison.getInstance().economy.balanceOf(p);
29+
double bal = user.getBalance();
2830
return "$" + bal;
31+
} else if (identifier.equalsIgnoreCase("version")) {
32+
return "v" + AntaresPrison.getInstance().getDescription().getVersion();
2933
} else if (identifier.equalsIgnoreCase("tier")) {
30-
List<String> tickets = AntaresPrison.getInstance().tickets.tickets.get(p.getUniqueId());
34+
List<String> tickets = user.getTickets();
3135
String tier = tickets.get(tickets.size() - 1).replace('_', ' ');
3236
return tier;
3337
} else {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package org.piotrwyrw.antares.prison;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.scheduler.BukkitRunnable;
6+
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
public class PrisonsUser {
11+
12+
private UUID uuid;
13+
private List<String> tickets;
14+
private double balance;
15+
private String lastCommand;
16+
private String lastMessage;
17+
18+
public PrisonsUser(UUID uuid, List<String> tickets, double balance) {
19+
this.tickets = tickets;
20+
this.balance = balance;
21+
this.uuid = uuid;
22+
this.lastCommand = "";
23+
this.lastMessage = "";
24+
}
25+
26+
/**
27+
* !! Use isOnline first for safety !!
28+
*/
29+
public Player getPlayer() {
30+
return Bukkit.getPlayer(uuid);
31+
}
32+
33+
public boolean isOnline() {
34+
return Bukkit.getPlayer(uuid) != null;
35+
}
36+
37+
public boolean hasTicket(String ticket) {
38+
return tickets.contains(ticket);
39+
}
40+
41+
public void setLastMessage(String message, boolean erase) {
42+
this.lastMessage = message;
43+
if (!erase)
44+
return;
45+
new BukkitRunnable(){
46+
47+
@Override
48+
public void run() {
49+
lastMessage = "";
50+
}
51+
}.runTaskLater(AntaresPrison.getInstance(), 20 * 20);
52+
}
53+
54+
public void setLastCommand(String command, boolean erase) {
55+
this.lastCommand = command;
56+
if (!erase)
57+
return;
58+
new BukkitRunnable(){
59+
60+
@Override
61+
public void run() {
62+
lastCommand = "";
63+
}
64+
}.runTaskLater(AntaresPrison.getInstance(), 20 * 20);
65+
}
66+
67+
public void addTicket(String ticket) {
68+
if (tickets.contains(ticket))
69+
return;
70+
tickets.add(ticket);
71+
}
72+
73+
public UUID getUuid() {
74+
return uuid;
75+
}
76+
77+
public void setUuid(UUID uuid) {
78+
this.uuid = uuid;
79+
}
80+
81+
public List<String> getTickets() {
82+
return tickets;
83+
}
84+
85+
public void setTickets(List<String> tickets) {
86+
this.tickets = tickets;
87+
}
88+
89+
public double getBalance() {
90+
return balance;
91+
}
92+
93+
public void setBalance(double balance) {
94+
this.balance = balance;
95+
}
96+
97+
public String getLastCommand() {
98+
return lastCommand;
99+
}
100+
101+
public String getLastMessage() {
102+
return lastMessage;
103+
}
104+
}

0 commit comments

Comments
 (0)