Skip to content

Commit e3773b2

Browse files
committed
Add license header
1 parent 3fd93e1 commit e3773b2

16 files changed

+530
-52
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
}
2626

2727
shadowJar {
28-
relocate('reactor', "io.github.simplex.reactor")
28+
relocate('reactor', "io.github.simplexdevelopment.reactor")
2929
exclude('io.github.simplexdevelopment.impl')
3030
}
3131

src/main/java/io/github/simplexdevelopment/api/Context.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

327
import org.jetbrains.annotations.NotNull;
@@ -8,6 +32,12 @@
832
import java.util.Collection;
933
import java.util.Objects;
1034

35+
/**
36+
* A glorified wrapper class which collects an element and abstracts it behind the Reactor API.
37+
*
38+
* @param <S> Any object type to wrap with this class.
39+
* @author SimplexDevelopment
40+
*/
1141
public interface Context<S> {
1242
/**
1343
* @return A Mono object which contains a single element represented by the definer of this Context class.

src/main/java/io/github/simplexdevelopment/api/ISchedule.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

27+
import io.github.simplexdevelopment.scheduler.SchedulingSystem;
328
import io.github.simplexdevelopment.scheduler.ServiceManager;
429
import org.jetbrains.annotations.NotNull;
530
import reactor.core.Disposable;
631
import reactor.core.publisher.Mono;
732

33+
/**
34+
* This interface contains surface level methods for the {@link SchedulingSystem} to use.
35+
*
36+
* @author SimplexDevelopment
37+
*/
838
public interface ISchedule {
939

1040
/**

src/main/java/io/github/simplexdevelopment/api/IService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

327
import io.github.simplexdevelopment.scheduler.ServicePool;
428
import org.bukkit.plugin.java.JavaPlugin;
529
import reactor.core.publisher.Mono;
630

31+
/**
32+
* Represents a service that can be registered to a {@link ServicePool}.
33+
* <p>
34+
* This interface provides surface level methods to be used by the {@link ServicePool}
35+
* associated to each service.
36+
*
37+
* @author SimplexDevelopment
38+
*/
739
public interface IService extends Runnable, Identifier {
840

941
/**

src/main/java/io/github/simplexdevelopment/api/Identifier.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

327
import java.util.UUID;
428

29+
/**
30+
* This interface provides a method for retrieving a name, unique identifier, and numerical id for a class.
31+
*
32+
* @author SimplexDevelopment
33+
*/
534
public interface Identifier {
635
/**
736
* @return The name of the identifiable object in a readable format.

src/main/java/io/github/simplexdevelopment/api/ServiceException.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

327
import java.util.function.Supplier;
428

29+
/**
30+
* This class is used to represent a service exception.
31+
* When a {@link IService} is called that has not been registered with a {@link io.github.simplexdevelopment.scheduler.ServicePool},
32+
* this exception will be thrown.
33+
*
34+
* @author SimplexDevelopment
35+
*/
536
public class ServiceException extends RuntimeException {
637
/**
738
* Constructs a new service exception which states the service is not present within any service pools.

src/main/java/io/github/simplexdevelopment/api/ServicePoolException.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.api;
226

27+
import io.github.simplexdevelopment.scheduler.ServicePool;
328
import org.jetbrains.annotations.Contract;
429
import org.jetbrains.annotations.NotNull;
530

631
import java.util.function.Supplier;
732

33+
/**
34+
* This class is used to represent a service pool exception.
35+
* This exception is thrown when a {@link ServicePool} is not found,
36+
* when {@link ServicePool#queueService(IService)} is called but the service is not registered with this pool,
37+
* or if the service pool is empty and {@link ServicePool#queueServices()} is called.
38+
*
39+
* @author SimplexDevelopment
40+
*/
841
public class ServicePoolException extends RuntimeException {
942
/**
1043
* Constructs a new generic service pool exception.

src/main/java/io/github/simplexdevelopment/impl/Main.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 SimplexDevelopment
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
package io.github.simplexdevelopment.impl;
226

327
import io.github.simplexdevelopment.scheduler.SchedulingSystem;
28+
import io.github.simplexdevelopment.scheduler.ServicePool;
429
import org.bukkit.plugin.java.JavaPlugin;
5-
import org.jetbrains.annotations.NotNull;
630
import reactor.core.Disposable;
731
import reactor.core.publisher.Flux;
832

@@ -19,8 +43,15 @@ public void onEnable() {
1943
// Plugin startup logic
2044
// Create a new instance of the scheduling system.
2145
this.scheduler = new SchedulingSystem<>(this);
46+
47+
// Creates new service pools.
48+
getScheduler().getServiceManager().subscribe(a -> {
49+
a.emptyBukkitServicePool("main_pool", this).subscribe();
50+
a.emptyServicePool("off_loader", true).subscribe();
51+
});
52+
2253
// This will register all the services and set our Flux<Disposable> object above.
23-
registerServices(new PoolHolder(this));
54+
registerServices("main_pool");
2455
}
2556

2657
@Override
@@ -34,22 +65,32 @@ public void onDisable() {
3465
});
3566
}
3667

37-
public void registerServices(@NotNull PoolHolder poolHolder) {
68+
public void registerServices(String poolName) {
3869
// This set will be used to set the Flux<Disposable> object
3970
// that will be used to stop the services when the plugin is disabled.
4071
Set<Disposable> dispos = new HashSet<>();
4172

73+
// Find the service pool we want to register our services to.
74+
ServicePool pool = scheduler.getServiceManager().map(a -> a.getServicePools()
75+
.filter(b -> b.getName().equalsIgnoreCase(poolName))
76+
.blockFirst())
77+
.block();
78+
79+
// Make sure the pool isn't null.
80+
if (pool == null) pool = new ServicePool(poolName, this);
81+
4282
// Register services here
43-
ServiceImpl impl = new ServiceImpl(this, poolHolder.getContext().block());
83+
ServiceImpl impl = new ServiceImpl(this, pool);
4484

4585
// This will register the service to the service pool.
4686
dispos.add(scheduler.getMainScheduler().schedule(impl));
4787
// OR
4888
scheduler.queue(impl).subscribe(dispos::add);
4989
// OR
5090
scheduler.getServiceManager()
51-
.flatMap(manager -> manager.createServicePool("newPool", impl))
52-
.subscribe(p -> p.queueService(impl).subscribe(dispos::add));
91+
.flatMap(manager -> manager.emptyBukkitServicePool("backup", this))
92+
.doOnNext(pool_a -> pool_a.getAssociatedServices().add(impl))
93+
.subscribe(pool_b -> pool_b.queueService(impl).subscribe(dispos::add));
5394

5495
// This will set the Flux<Disposable> object on our previously made set, so that we can use it later on.
5596
disposables = Flux.fromIterable(dispos);

src/main/java/io/github/simplexdevelopment/impl/PoolHolder.java

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

0 commit comments

Comments
 (0)