Skip to content
This repository was archived by the owner on Jun 10, 2023. It is now read-only.

Commit 3875f71

Browse files
committed
Towny is working now
1 parent 81ab66d commit 3875f71

98 files changed

Lines changed: 3920 additions & 694 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
package org.ve;
2+
3+
import net.milkbowl.vault.economy.Economy;
4+
import net.milkbowl.vault.economy.EconomyResponse;
5+
import org.bonge.launch.BongeLaunch;
6+
import org.bukkit.Bukkit;
7+
import org.bukkit.OfflinePlayer;
8+
import org.spongepowered.api.Sponge;
9+
import org.spongepowered.api.event.cause.Cause;
10+
import org.spongepowered.api.event.cause.EventContext;
11+
import org.spongepowered.api.event.cause.EventContextKeys;
12+
import org.spongepowered.api.service.ProviderRegistration;
13+
import org.spongepowered.api.service.economy.Currency;
14+
import org.spongepowered.api.service.economy.EconomyService;
15+
import org.spongepowered.api.service.economy.account.UniqueAccount;
16+
import org.spongepowered.api.service.economy.transaction.ResultType;
17+
import org.spongepowered.api.service.economy.transaction.TransactionResult;
18+
19+
import java.io.IOException;
20+
import java.math.BigDecimal;
21+
import java.util.Collections;
22+
import java.util.List;
23+
import java.util.Optional;
24+
25+
public class BongeEco implements Economy {
26+
27+
private Currency currency;
28+
29+
public ProviderRegistration<EconomyService> getSpongeEco() throws IOException {
30+
Optional<ProviderRegistration<EconomyService>> opService = Sponge.getServiceManager().getRegistration(EconomyService.class);
31+
if(!opService.isPresent()){
32+
throw new IOException("No economy service found for Sponge");
33+
}
34+
if(this.currency == null){
35+
this.currency = opService.get().getProvider().getDefaultCurrency();
36+
}
37+
return opService.get();
38+
}
39+
40+
public EconomyResponse convert(TransactionResult result){
41+
EconomyResponse.ResponseType type = EconomyResponse.ResponseType.FAILURE;
42+
String errorMessage = result.getType().getName();
43+
if(result.getResult().equals(ResultType.SUCCESS)){
44+
type = EconomyResponse.ResponseType.SUCCESS;
45+
errorMessage = null;
46+
}
47+
return new EconomyResponse(result.getAmount().doubleValue(), result.getAccount().getBalance(result.getCurrency()).doubleValue(), type, errorMessage);
48+
}
49+
50+
public UniqueAccount getSpongeAccount(OfflinePlayer player) throws IOException{
51+
ProviderRegistration<EconomyService> service = this.getSpongeEco();
52+
Optional<UniqueAccount> opAccount = service.getProvider().getOrCreateAccount(player.getUniqueId());
53+
if(opAccount.isPresent()){
54+
return opAccount.get();
55+
}
56+
throw new IOException("Can not create new Sponge account for economy");
57+
}
58+
59+
@Override
60+
public boolean isEnabled() {
61+
try {
62+
getSpongeEco();
63+
return true;
64+
} catch (IOException e) {
65+
return false;
66+
}
67+
}
68+
69+
@Override
70+
public String getName() {
71+
return "BongeEco";
72+
}
73+
74+
@Override
75+
public boolean hasBankSupport() {
76+
return false;
77+
}
78+
79+
@Override
80+
public int fractionalDigits() {
81+
return 0;
82+
}
83+
84+
@Override
85+
public String format(double v) {
86+
return null;
87+
}
88+
89+
@Override
90+
public String currencyNamePlural() {
91+
return null;
92+
}
93+
94+
@Override
95+
public String currencyNameSingular() {
96+
return null;
97+
}
98+
99+
@Override
100+
public boolean hasAccount(String s) {
101+
return this.hasAccount(Bukkit.getOfflinePlayer(s));
102+
}
103+
104+
@Override
105+
public boolean hasAccount(OfflinePlayer offlinePlayer) {
106+
try {
107+
return this.getSpongeEco().getProvider().hasAccount(offlinePlayer.getUniqueId());
108+
} catch (IOException e) {
109+
return false;
110+
}
111+
112+
}
113+
114+
@Override
115+
public boolean hasAccount(String s, String s1) {
116+
return this.hasAccount(Bukkit.getOfflinePlayer(s), s1);
117+
}
118+
119+
@Override
120+
public boolean hasAccount(OfflinePlayer offlinePlayer, String s) {
121+
return this.hasAccount(offlinePlayer);
122+
}
123+
124+
@Override
125+
public double getBalance(String s) {
126+
return this.getBalance(Bukkit.getOfflinePlayer(s));
127+
}
128+
129+
@Override
130+
public double getBalance(OfflinePlayer offlinePlayer) {
131+
try {
132+
return this.getSpongeAccount(offlinePlayer).getBalance(this.currency).doubleValue();
133+
} catch (IOException e) {
134+
return 0.0;
135+
}
136+
}
137+
138+
@Override
139+
public double getBalance(String s, String s1) {
140+
return this.getBalance(Bukkit.getOfflinePlayer(s), s1);
141+
}
142+
143+
@Override
144+
public double getBalance(OfflinePlayer offlinePlayer, String s) {
145+
return this.getBalance(offlinePlayer);
146+
}
147+
148+
@Override
149+
public boolean has(String s, double v) {
150+
return this.has(Bukkit.getOfflinePlayer(s), v);
151+
}
152+
153+
@Override
154+
public boolean has(OfflinePlayer offlinePlayer, double v) {
155+
return this.getBalance(offlinePlayer) >= v;
156+
}
157+
158+
@Override
159+
public boolean has(String s, String s1, double v) {
160+
return this.has(Bukkit.getOfflinePlayer(s), s1, v);
161+
}
162+
163+
@Override
164+
public boolean has(OfflinePlayer offlinePlayer, String s, double v) {
165+
return this.has(offlinePlayer, v);
166+
}
167+
168+
@Override
169+
public EconomyResponse withdrawPlayer(String s, double v) {
170+
return this.withdrawPlayer(s, v);
171+
}
172+
173+
@Override
174+
public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, double v) {
175+
Cause cause = Cause.builder().append(offlinePlayer).build(EventContext.builder().add(EventContextKeys.PLUGIN, BongeLaunch.getContainer()).build());
176+
try {
177+
return this.convert(this.getSpongeAccount(offlinePlayer).withdraw(this.currency, new BigDecimal(v), cause));
178+
} catch (IOException e) {
179+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Unknown Sponge economy service");
180+
}
181+
}
182+
183+
@Override
184+
public EconomyResponse withdrawPlayer(String s, String s1, double v) {
185+
return this.withdrawPlayer(s, s1, v);
186+
}
187+
188+
@Override
189+
public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, String s, double v) {
190+
return this.withdrawPlayer(offlinePlayer, v);
191+
}
192+
193+
@Override
194+
public EconomyResponse depositPlayer(String s, double v) {
195+
return depositPlayer(Bukkit.getOfflinePlayer(s), v);
196+
}
197+
198+
@Override
199+
public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, double v) {
200+
Cause cause = Cause.builder().append(offlinePlayer).build(EventContext.builder().add(EventContextKeys.PLUGIN, BongeLaunch.getContainer()).build());
201+
try {
202+
return this.convert(this.getSpongeAccount(offlinePlayer).deposit(this.currency, new BigDecimal(v), cause));
203+
} catch (IOException e) {
204+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Unknown Sponge economy service");
205+
}
206+
}
207+
208+
@Override
209+
public EconomyResponse depositPlayer(String s, String s1, double v) {
210+
return this.depositPlayer(s, v);
211+
}
212+
213+
@Override
214+
public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, String s, double v) {
215+
return this.depositPlayer(offlinePlayer, v);
216+
}
217+
218+
@Override
219+
public EconomyResponse createBank(String s, String s1) {
220+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
221+
}
222+
223+
@Override
224+
public EconomyResponse createBank(String s, OfflinePlayer offlinePlayer) {
225+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
226+
}
227+
228+
@Override
229+
public EconomyResponse deleteBank(String s) {
230+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
231+
}
232+
233+
@Override
234+
public EconomyResponse bankBalance(String s) {
235+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
236+
}
237+
238+
@Override
239+
public EconomyResponse bankHas(String s, double v) {
240+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
241+
}
242+
243+
@Override
244+
public EconomyResponse bankWithdraw(String s, double v) {
245+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
246+
}
247+
248+
@Override
249+
public EconomyResponse bankDeposit(String s, double v) {
250+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
251+
}
252+
253+
@Override
254+
public EconomyResponse isBankOwner(String s, String s1) {
255+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
256+
}
257+
258+
@Override
259+
public EconomyResponse isBankOwner(String s, OfflinePlayer offlinePlayer) {
260+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
261+
}
262+
263+
@Override
264+
public EconomyResponse isBankMember(String s, String s1) {
265+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
266+
}
267+
268+
@Override
269+
public EconomyResponse isBankMember(String s, OfflinePlayer offlinePlayer) {
270+
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "No bank support in Sponge");
271+
}
272+
273+
@Override
274+
public List<String> getBanks() {
275+
return Collections.EMPTY_LIST;
276+
}
277+
278+
@Override
279+
public boolean createPlayerAccount(String s) {
280+
return this.createPlayerAccount(Bukkit.getOfflinePlayer(s));
281+
}
282+
283+
@Override
284+
public boolean createPlayerAccount(OfflinePlayer offlinePlayer) {
285+
try {
286+
this.getSpongeAccount(offlinePlayer);
287+
return true;
288+
} catch (IOException e) {
289+
return false;
290+
}
291+
}
292+
293+
@Override
294+
public boolean createPlayerAccount(String s, String s1) {
295+
return this.createPlayerAccount(Bukkit.getOfflinePlayer(s), s1);
296+
}
297+
298+
@Override
299+
public boolean createPlayerAccount(OfflinePlayer offlinePlayer, String s) {
300+
return this.createPlayerAccount(offlinePlayer);
301+
}
302+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.ve;
2+
3+
import net.milkbowl.vault.economy.Economy;
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.plugin.ServicePriority;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
public class BongeVault extends JavaPlugin {
9+
10+
public void onEnable(){
11+
Bukkit.getServer().getServicesManager().register(Economy.class, new BongeEco(), this, ServicePriority.Highest);
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: BongeVault
2+
main: org.ve.BongeVault
3+
version: 1.0-SNAPSHOT
4+
api-version: 1.13
5+
depend:
6+
- Vault

src/main/java/org/bonge/Bonge.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,36 @@ public <B, S> Set<Converter<B, S>> getConverts(B value, Class<S> sClass){
4343

4444
public <B, S> B convert(Class<B> clazz, S value) throws IOException{
4545
Set<Converter<B, S>> set = this.getConverts(clazz, value);
46+
if(set.isEmpty()){
47+
throw new IOException("No valid converts to convert Bukkit: " + clazz.getSimpleName() + " to Sponge: " + value.getClass().getSimpleName());
48+
}
49+
IOException e2 = null;
4650
for(Converter<B, S> converter : set){
4751
try{
4852
return converter.to(value);
49-
}catch (Throwable e){
53+
}catch (IOException e){
54+
e2 = e;
5055
continue;
5156
}
5257
}
53-
throw new IOException("Could not convert " + value + " to " + clazz.getName());
58+
throw e2;
5459
}
5560

5661
public <B, S> S convert(B value, Class<S> clazz) throws IOException{
5762
Set<Converter<B, S>> set = this.getConverts(value, clazz);
63+
if(set.isEmpty()){
64+
throw new IOException("No valid converts to convert Bukkit: " + value.getClass().getSimpleName() + " to Sponge: " + clazz.getSimpleName());
65+
}
66+
IOException e2 = null;
5867
for(Converter<B, S> converter : set){
5968
try{
6069
return converter.from(value);
61-
}catch (Throwable e){
70+
}catch (IOException e){
71+
e2 = e;
6272
continue;
6373
}
6474
}
65-
throw new IOException("Could not convert " + value + " to " + clazz.getName());
75+
throw e2;
6676
}
6777

6878
public Set<Material> getMaterials(){

src/main/java/org/bonge/bukkit/r1_13/block/BongeBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public int getZ() {
129129
@NotNull
130130
@Override
131131
public org.bukkit.Location getLocation() {
132-
return new BongeLocation(this.spongeValue);
132+
return new BongeLocation(this.spongeValue.getExtent().getLocation(this.spongeValue.getBlockX(), this.spongeValue.getBlockY(), this.spongeValue.getBlockZ()));
133133
}
134134

135135
@Nullable

src/main/java/org/bonge/bukkit/r1_13/block/BongeBlockSnapshot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bonge.Bonge;
44
import org.bonge.bukkit.r1_13.block.data.BongeAbstractBlockData;
5+
import org.bonge.bukkit.r1_13.block.state.BongeBlockState;
56
import org.bonge.bukkit.r1_13.world.BongeLocation;
67
import org.bonge.bukkit.r1_13.world.BongeWorld;
78
import org.bonge.util.exception.NotImplementedException;

0 commit comments

Comments
 (0)