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

Commit 98b7357

Browse files
authored
Merge pull request #99 from CloudNetService/development
Merge development into master branch
2 parents 74d5490 + b4a54ec commit 98b7357

File tree

22 files changed

+153
-102
lines changed

22 files changed

+153
-102
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pipeline {
1515
}
1616
stage('Version') {
1717
steps {
18-
sh 'mvn versions:set -DnewVersion=2.1.14.2'
18+
sh 'mvn versions:set -DnewVersion=2.1.14.3'
1919
}
2020
}
2121
stage('Compile') {

cloudnet-api/cloudnet-api-bridge/src/main/java/de/dytanic/cloudnet/bridge/BukkitBootstrap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void checkRegistryAccess()
105105
{
106106
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
107107
Class.forName("de.dytanic.cloudnet.bridge.internal.chat.DocumentRegistry").getMethod("fire").invoke(null);
108-
} catch (Exception ex)
108+
} catch (Exception ignored)
109109
{
110110
}
111111
}

cloudnet-api/cloudnet-api-bridge/src/main/java/de/dytanic/cloudnet/bridge/CloudProxy.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,14 @@ public void onServerRemove(ServerInfo serverInfo)
374374
if (serverInfo == null) return;
375375

376376
ProxyServer.getInstance().getPluginManager().callEvent(new ProxiedServerRemoveEvent(serverInfo));
377-
ProxyServer.getInstance().getServers().remove(serverInfo.getServiceId().getServerId());
377+
378+
try
379+
{
380+
ProxyServer.getInstance().getServers().remove(serverInfo.getServiceId().getServerId());
381+
} catch (Throwable ignored)
382+
{
383+
}
384+
378385
cachedServers.remove(serverInfo.getServiceId().getServerId());
379386

380387
if (serverInfo.getServiceId().getGroup().equalsIgnoreCase(getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))

cloudnet-api/cloudnet-api-bridge/src/main/java/de/dytanic/cloudnet/bridge/internal/listener/bukkit/BukkitListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import de.dytanic.cloudnet.api.CloudAPI;
88
import de.dytanic.cloudnet.bridge.CloudServer;
99
import de.dytanic.cloudnet.bridge.event.bukkit.BukkitSubChannelMessageEvent;
10-
import de.dytanic.cloudnet.bridge.internal.util.CloudPermissble;
10+
import de.dytanic.cloudnet.bridge.internal.util.CloudPermissible;
1111
import de.dytanic.cloudnet.bridge.internal.util.ReflectionUtil;
1212
import de.dytanic.cloudnet.lib.player.CloudPlayer;
1313
import de.dytanic.cloudnet.lib.player.permission.GroupEntityData;
@@ -97,8 +97,8 @@ public void handleFirst(PlayerLoginEvent event)
9797
else field = Class.forName("net.glowstone.entity.GlowHumanEntity").getDeclaredField("permissions");
9898

9999
field.setAccessible(true);
100-
final CloudPermissble cloudPermissble = new CloudPermissble(event.getPlayer());
101-
field.set(event.getPlayer(), cloudPermissble);
100+
final CloudPermissible cloudPermissible = new CloudPermissible(event.getPlayer());
101+
field.set(event.getPlayer(), cloudPermissible);
102102
} catch (Exception ex)
103103
{
104104
ex.printStackTrace();

cloudnet-api/cloudnet-api-bridge/src/main/java/de/dytanic/cloudnet/bridge/internal/serverselectors/SignSelector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public void onServerAdd(ServerInfo serverInfo)
799799
changeBlock(location, signLayout.getBlockId(), signLayout.getSubId());
800800
} else
801801
{
802-
sign.setServerInfo(null);
802+
newSign.setServerInfo(null);
803803
SignLayout signLayout = getSearchingLayout(((ThreadImpl) worker).animationTick);
804804
String[] layout = updateOfflineAndMaintenance(signLayout.getSignLayout().clone(), sign);
805805
for (Player all : Bukkit.getOnlinePlayers())
@@ -971,4 +971,4 @@ public void run()
971971
}
972972
}
973973
}
974-
}
974+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
/**
2121
* Created by Tareko on 18.08.2017.
2222
*/
23-
public class CloudPermissble extends PermissibleBase {
23+
public class CloudPermissible extends PermissibleBase {
2424

2525
private UUID uniqueId;
2626

27-
public CloudPermissble(Player player)
27+
public CloudPermissible(Player player)
2828
{
2929
super(player);
3030
this.uniqueId = player.getUniqueId();

cloudnet-cord/cloudnet-cloudflare/src/main/java/de/dytanic/cloudnet/cloudflare/CloudFlareService.java

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
import de.dytanic.cloudnet.cloudflare.util.DNSType;
1313
import de.dytanic.cloudnet.cloudflare.util.DefaultDNSRecord;
1414
import de.dytanic.cloudnet.cloudflare.util.SRVRecord;
15+
import de.dytanic.cloudnet.lib.MultiValue;
1516
import de.dytanic.cloudnet.lib.NetworkUtils;
16-
import de.dytanic.cloudnet.lib.database.Database;
1717
import de.dytanic.cloudnet.lib.server.ProxyGroup;
1818
import de.dytanic.cloudnet.lib.server.ProxyProcessMeta;
1919
import de.dytanic.cloudnet.lib.service.SimpledWrapperInfo;
20+
import de.dytanic.cloudnet.lib.utility.Acceptable;
2021
import de.dytanic.cloudnet.lib.utility.CollectionWrapper;
2122
import de.dytanic.cloudnet.lib.utility.document.Document;
2223
import lombok.Getter;
@@ -42,9 +43,9 @@ public class CloudFlareService {
4243
private Collection<CloudFlareConfig> cloudFlareConfigs;
4344

4445
// WrapperId DNSRecord
45-
private final Map<String, PostResponse>
46-
ipARecords = NetworkUtils.newConcurrentHashMap(),
47-
bungeeSRVRecords = NetworkUtils.newConcurrentHashMap();
46+
private final Map<String, MultiValue<PostResponse, String>> ipARecords = NetworkUtils.newConcurrentHashMap();
47+
48+
private final Map<String, MultiValue<PostResponse, String>> bungeeSRVRecords = NetworkUtils.newConcurrentHashMap();
4849

4950
/**
5051
* Constructs a new CloudFlare Service module with a given configuration.
@@ -61,12 +62,8 @@ public CloudFlareService(Collection<CloudFlareConfig> cloudFlareConfigs)
6162
@Deprecated
6263
public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<String, ProxyGroup> groups, CloudFlareDatabase cloudFlareDatabase)
6364
{
64-
for (PostResponse id : cloudFlareDatabase.getAndRemove().values())
65-
this.deleteRecord(id);
66-
67-
for (String key : cloudFlareDatabase.getAll())
68-
if (!key.equalsIgnoreCase(Database.UNIQUE_NAME_KEY) && !wrapperInfoMap.containsKey(key))
69-
deleteRecord(cloudFlareDatabase.getResponse(key));
65+
for (MultiValue<PostResponse, String> id : cloudFlareDatabase.getAndRemove().values())
66+
this.deleteRecord(id.getFirst());
7067

7168
for (CloudFlareConfig cloudFlareConfig : this.cloudFlareConfigs)
7269
if (cloudFlareConfig.isEnabled())
@@ -75,15 +72,15 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str
7572
ProxyGroup proxyGroup = groups.get(cloudFlareProxyGroup.getName());
7673
for (String wrapper : proxyGroup.getWrapper())
7774
{
78-
if (!cloudFlareDatabase.contains(wrapper))
75+
if (!cloudFlareDatabase.contains(cloudFlareConfig, wrapper))
7976
{
8077
String host = wrapperInfoMap.get(wrapper).getHostName();
8178
DNSRecord dnsRecord = new DefaultDNSRecord(DNSType.A, wrapper + "." + cloudFlareConfig.getDomainName(), host, new Document().obj());
8279
if (!ipARecords.containsKey(wrapper))
8380
{
8481
PostResponse postResponse = this.createRecord(cloudFlareConfig, dnsRecord);
85-
ipARecords.put(wrapper, postResponse);
86-
cloudFlareDatabase.putPostResponse(wrapper, postResponse);
82+
ipARecords.put(postResponse.getId(), new MultiValue<>(postResponse, wrapper));
83+
cloudFlareDatabase.putPostResponse(new MultiValue<>(postResponse, wrapper));
8784
NetworkUtils.sleepUninterruptedly(400);
8885
}
8986
}
@@ -94,16 +91,22 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str
9491

9592
public boolean shutdown(CloudFlareDatabase cloudFlareDatabase)
9693
{
97-
for (PostResponse postResponse : this.bungeeSRVRecords.values())
94+
for (MultiValue<PostResponse, String> postResponse : this.bungeeSRVRecords.values())
9895
{
99-
this.deleteRecord(postResponse);
100-
NetworkUtils.sleepUninterruptedly(450);
96+
try
97+
{
98+
this.deleteRecord(postResponse.getFirst());
99+
NetworkUtils.sleepUninterruptedly(500);
100+
} catch (Exception ex)
101+
{
102+
ex.printStackTrace();
103+
}
101104
}
102105

103-
for (PostResponse id : cloudFlareDatabase.getAndRemove().values())
106+
for (MultiValue<PostResponse, String> id : cloudFlareDatabase.getAndRemove().values())
104107
{
105-
this.deleteRecord(id);
106-
NetworkUtils.sleepUninterruptedly(450);
108+
this.deleteRecord(id.getFirst());
109+
NetworkUtils.sleepUninterruptedly(500);
107110
}
108111
return true;
109112
}
@@ -163,9 +166,9 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
163166
proxyServer.getServiceId().getWrapperId() + "." + cloudFlareConfig.getDomainName()
164167
);
165168
}
166-
PostResponse postResponse1 = this.createRecord(cloudFlareConfig, srvRecord);
167-
cloudFlareDatabase.add(postResponse1);
168-
this.bungeeSRVRecords.put(proxyServer.getServiceId().getServerId(), postResponse1);
169+
PostResponse postResponse = this.createRecord(cloudFlareConfig, srvRecord);
170+
cloudFlareDatabase.add(postResponse);
171+
this.bungeeSRVRecords.put(postResponse.getId(), new MultiValue<>(postResponse, proxyServer.getServiceId().getServerId()));
169172
}
170173
}
171174
}
@@ -178,13 +181,36 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
178181
*/
179182
public void removeProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlareDatabase)
180183
{
181-
if (!bungeeSRVRecords.containsKey(proxyServer.getServiceId().getServerId())) return;
184+
//if (!bungeeSRVRecords.containsKey(proxyServer.getServiceId().getServerId())) return;
182185

183-
PostResponse postResponse = bungeeSRVRecords.get(proxyServer.getServiceId().getServerId());
184-
if (postResponse != null)
186+
while (true)
185187
{
186-
cloudFlareDatabase.remove(postResponse.getId());
187-
deleteRecord(postResponse);
188+
Collection<MultiValue<PostResponse, String>> postResponses = CollectionWrapper.filterMany(bungeeSRVRecords.values(), new Acceptable<MultiValue<PostResponse, String>>() {
189+
@Override
190+
public boolean isAccepted(MultiValue<PostResponse, String> postResponseStringMultiValue)
191+
{
192+
return postResponseStringMultiValue.getSecond().equalsIgnoreCase(proxyServer.getServiceId().getServerId());
193+
}
194+
});
195+
196+
//MultiValue<PostResponse, String> postResponse = bungeeSRVRecords.get(proxyServer.getServiceId().getServerId());
197+
/*
198+
if (postResponse != null)
199+
{
200+
cloudFlareDatabase.remove(postResponse.getFirst().getId());
201+
deleteRecord(postResponse.getFirst());
202+
} else break;
203+
*/
204+
205+
for (MultiValue<PostResponse, String> postResponse : postResponses)
206+
if (postResponse != null)
207+
{
208+
bungeeSRVRecords.remove(postResponse.getSecond());
209+
cloudFlareDatabase.remove(postResponse.getFirst().getId());
210+
deleteRecord(postResponse.getFirst());
211+
212+
NetworkUtils.sleepUninterruptedly(500);
213+
}
188214
}
189215
}
190216

@@ -209,6 +235,7 @@ public PostResponse createRecord(CloudFlareConfig cloudFlareConfig, DNSRecord dn
209235
httpPost.setRequestProperty("Content-Type", "application/json");
210236
httpPost.setDoOutput(true);
211237
httpPost.connect();
238+
212239
try (DataOutputStream dataOutputStream = new DataOutputStream(httpPost.getOutputStream()))
213240
{
214241
dataOutputStream.writeBytes(values);
@@ -231,6 +258,7 @@ public PostResponse createRecord(CloudFlareConfig cloudFlareConfig, DNSRecord dn
231258
{
232259
e.printStackTrace();
233260
}
261+
234262
return null;
235263
}
236264

@@ -245,12 +273,14 @@ public void deleteRecord(PostResponse postResponse)
245273
try
246274
{
247275
HttpURLConnection delete = (HttpURLConnection) new URL(PREFIX_URL + "zones/" + postResponse.getCloudFlareConfig().getZoneId() + "/dns_records/" + postResponse.getId()).openConnection();
276+
248277
delete.setRequestMethod("DELETE");
249278
delete.setRequestProperty("X-Auth-Email", postResponse.getCloudFlareConfig().getEmail());
250279
delete.setRequestProperty("X-Auth-Key", postResponse.getCloudFlareConfig().getToken());
251280
delete.setRequestProperty("Accept", "application/json");
252281
delete.setRequestProperty("Content-Type", "application/json");
253282
delete.connect();
283+
254284
try (InputStream inputStream = delete.getInputStream())
255285
{
256286
JsonObject jsonObject = toJsonInput(inputStream);
@@ -259,6 +289,7 @@ public void deleteRecord(PostResponse postResponse)
259289
System.out.println(prefix + " DNSRecord [" + postResponse.getId() + "] was removed");
260290
}
261291
}
292+
262293
delete.disconnect();
263294
} catch (Exception ex)
264295
{

cloudnet-cord/cloudnet-cloudflare/src/main/java/de/dytanic/cloudnet/cloudflare/database/CloudFlareDatabase.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package de.dytanic.cloudnet.cloudflare.database;
66

77
import com.google.gson.reflect.TypeToken;
8+
import de.dytanic.cloudnet.cloudflare.CloudFlareConfig;
89
import de.dytanic.cloudnet.cloudflare.PostResponse;
910
import de.dytanic.cloudnet.database.DatabaseUsable;
11+
import de.dytanic.cloudnet.lib.MultiValue;
1012
import de.dytanic.cloudnet.lib.database.Database;
1113
import de.dytanic.cloudnet.lib.database.DatabaseDocument;
1214
import de.dytanic.cloudnet.lib.utility.MapWrapper;
@@ -42,17 +44,44 @@ public Collection<String> getAll()
4244
return collection;
4345
}
4446

45-
public void putPostResponse(String wrapper, PostResponse postResponse)
47+
public void putPostResponse(MultiValue<PostResponse, String> postResponse)
4648
{
4749
Document document = database.getDocument(CLOUDFLARE_CACHE);
48-
document.append(wrapper, postResponse);
50+
document.append(postResponse.getFirst().getId(), postResponse);
4951
database.insert(document);
5052
}
5153

52-
public boolean contains(String wrapper)
54+
public boolean contains(CloudFlareConfig cloudFlareConfig, String wrapper)
5355
{
5456
Document document = database.getDocument(CLOUDFLARE_CACHE);
55-
return document.contains(wrapper);
57+
58+
/*
59+
Map<String, MultiValue<PostResponse, String>> responses = document.getObject("requests", new TypeToken<Map<String, MultiValue<PostResponse, String>>>() {
60+
}.getType());
61+
*/
62+
63+
/*
64+
return CollectionWrapper.filter(responses.values(), new Acceptable<MultiValue<PostResponse, String>>() {
65+
@Override
66+
public boolean isAccepted(MultiValue<PostResponse, String> value)
67+
{
68+
return value.getSecond().equalsIgnoreCase(wrapper) && value.getFirst().getCloudFlareConfig().getDomainName().equalsIgnoreCase(cloudFlareConfig.getDomainName());
69+
}
70+
}) != null;
71+
*/
72+
73+
for (String key : document.keys())
74+
if (!key.equalsIgnoreCase(Database.UNIQUE_NAME_KEY))
75+
{
76+
MultiValue<PostResponse, String> value = document.getObject(key, new TypeToken<MultiValue<PostResponse, String>>() {
77+
}.getType());
78+
79+
if (value != null && value.getSecond().equalsIgnoreCase(wrapper) && value.getFirst().getCloudFlareConfig().getDomainName().equalsIgnoreCase(cloudFlareConfig.getDomainName()))
80+
return true;
81+
}
82+
83+
return false;
84+
//return document.contains(wrapper);
5685
}
5786

5887
public void remove(String wrapper)
@@ -102,18 +131,17 @@ public void remove(PostResponse postResponse)
102131
database.insert(document);
103132
}
104133

105-
public Map<String, PostResponse> getAndRemove()
134+
public Map<String, MultiValue<PostResponse, String>> getAndRemove()
106135
{
107136
Document document = database.getDocument(CLOUDFLARE_CACHE_REQ);
108137
if (document.contains("requests"))
109138
{
110-
Map<String, PostResponse> responses = document.getObject("requests", new TypeToken<Map<String, PostResponse>>() {
139+
Map<String, MultiValue<PostResponse, String>> responses = document.getObject("requests", new TypeToken<Map<String, MultiValue<PostResponse, String>>>() {
111140
}.getType());
112-
document.append("requests", new HashMap<>(0));
141+
document.append("requests", Collections.EMPTY_MAP);
113142
database.insert(document);
114143
return responses;
115144
}
116145
return Collections.EMPTY_MAP;
117146
}
118-
119-
}
147+
}

cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandShutdown.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void run(ProxyServer obj)
7979
sender.sendMessage("Group doesn't exist");
8080
return;
8181
}
82-
if (args[0].equalsIgnoreCase("server"))
82+
if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("-s"))
8383
{
8484
MinecraftServer proxyServer = CloudNet.getInstance().getServer(args[1]);
8585
if (proxyServer != null)
@@ -99,7 +99,7 @@ public void run(ProxyServer obj)
9999
}
100100
return;
101101
}
102-
if (args[0].equalsIgnoreCase("proxy"))
102+
if (args[0].equalsIgnoreCase("proxy") || args[0].equalsIgnoreCase("-p"))
103103
{
104104
ProxyServer proxyServer = CloudNet.getInstance().getProxy(args[1]);
105105
if (proxyServer != null)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22
# Copyright (c) Tarek Hosni El Alaoui 2017
33
#
4-
CloudNet-Service-PermissionModule=1.0.0.1
5-
CloudNet-Service-MobModule=1.0.0.1
6-
CloudNet-Service-SignsModule=1.0.0.1
7-
CloudNet-Service-CloudFlareModule=1.0.0.1
8-
CloudNet-Service-NotifyServiceModule=1.0.0.1
4+
CloudNet-Service-PermissionModule=1.0.0.2
5+
CloudNet-Service-MobModule=1.0.0.2
6+
CloudNet-Service-SignsModule=1.0.0.2
7+
CloudNet-Service-CloudFlareModule=1.0.0.2
8+
CloudNet-Service-NotifyServiceModule=1.0.0.2

0 commit comments

Comments
 (0)