├── .gitignore ├── LICENSE ├── README.MD ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── blurengine │ │ └── blur │ │ ├── Blur.java │ │ ├── BlurListener.kt │ │ ├── BlurPlayerManager.java │ │ ├── BlurPlugin.java │ │ ├── BlurSettings.java │ │ ├── commands │ │ ├── BlurCommandProviders.kt │ │ └── BlurCommands.java │ │ ├── components │ │ ├── cooldown │ │ │ └── Cooldowns.kt │ │ ├── killstreak │ │ │ └── BasicPvpComponent.kt │ │ └── shared │ │ │ ├── BlockRestore.kt │ │ │ ├── EntityFreezer.kt │ │ │ ├── EntityRemover.kt │ │ │ ├── ExtentGuard.kt │ │ │ └── PotionEffectManager.kt │ │ ├── countdown │ │ ├── AbstractCountdown.java │ │ ├── Countdown.java │ │ ├── CountdownWithEXP.java │ │ └── GlobalGameCountdown.java │ │ ├── effect │ │ └── BlurEffect.kt │ │ ├── events │ │ ├── players │ │ │ ├── BlurPlayerDeathEvent.java │ │ │ ├── BlurPlayerEvent.java │ │ │ ├── BlurPlayerRespawnEvent.java │ │ │ ├── PlayerDamagePlayerEvent.java │ │ │ ├── PlayerJoinSessionEvent.java │ │ │ ├── PlayerKilledEvent.java │ │ │ ├── PlayerLeaveSessionEvent.java │ │ │ ├── PlayerMoveBlockEvent.java │ │ │ ├── PlayerPostLeaveSessionEvent.java │ │ │ ├── PlayerPreJoinSessionEvent.java │ │ │ └── PlayerSwitchSessionEvent.kt │ │ └── session │ │ │ ├── BlurSessionEvent.java │ │ │ ├── SessionEnableEvent.java │ │ │ ├── SessionLoadEvent.java │ │ │ ├── SessionPreLoadEvent.java │ │ │ ├── SessionStartEvent.java │ │ │ └── SessionStopEvent.kt │ │ ├── framework │ │ ├── AbstractComponent.java │ │ ├── BlurSerializer.java │ │ ├── Component.java │ │ ├── ComponentState.java │ │ ├── InternalModule.java │ │ ├── InvalidModuleDataException.java │ │ ├── Module.java │ │ ├── ModuleData.java │ │ ├── ModuleInfo.java │ │ ├── ModuleLoadType.java │ │ ├── ModuleLoader.java │ │ ├── ModuleManager.java │ │ ├── ModuleNameHelper.java │ │ ├── ModuleParseException.java │ │ ├── SerializedModule.java │ │ ├── SessionHelperInterface.java │ │ ├── SharedComponent.java │ │ ├── WorldModule.java │ │ ├── metadata │ │ │ ├── BasicMetadataStorage.java │ │ │ ├── MetadataHolder.java │ │ │ ├── MetadataStorage.java │ │ │ ├── auto │ │ │ │ ├── AbstractAutoMetadataCreator.java │ │ │ │ └── MetadataCreator.java │ │ │ ├── playerdata │ │ │ │ ├── PlayerAutoMetadataCreator.java │ │ │ │ ├── PlayerData.java │ │ │ │ └── PlayerDataCreator.java │ │ │ └── teamdata │ │ │ │ ├── TeamAutoMetadataCreator.java │ │ │ │ ├── TeamData.java │ │ │ │ └── TeamDataCreator.java │ │ ├── serializer │ │ │ ├── ModuleNotFoundException.java │ │ │ └── ModuleSerializer.java │ │ └── ticking │ │ │ ├── BAutoInt.java │ │ │ ├── Tick.java │ │ │ ├── TickField.java │ │ │ ├── TickFieldGenerated.java │ │ │ ├── TickFieldHolder.java │ │ │ └── TickMethodsCache.java │ │ ├── inventory │ │ ├── InventoryLayout.java │ │ └── SlotType.java │ │ ├── modules │ │ ├── BoundariesModule.java │ │ ├── DummyModule.java │ │ ├── FixedHungerModule.java │ │ ├── InvulnerableModule.java │ │ ├── RandomCompassTargetModule.java │ │ ├── SetBlocksModule.java │ │ ├── WorldProtectModule.kt │ │ ├── checkpoints │ │ │ └── CheckpointsModule.kt │ │ ├── controlpoints │ │ │ ├── ControlPointCapturedEvent.java │ │ │ ├── ControlPointEnterEvent.java │ │ │ ├── ControlPointExitEvent.java │ │ │ ├── ControlPointLostEvent.java │ │ │ ├── ControlPointProgressResetEvent.java │ │ │ ├── ControlPointProgressTickEvent.java │ │ │ └── ControlPointsModule.kt │ │ ├── extents │ │ │ ├── AutoCircleExtent.java │ │ │ ├── BlockExtent.java │ │ │ ├── CuboidExtent.java │ │ │ ├── CylinderExtent.java │ │ │ ├── DirectionalExtent.kt │ │ │ ├── Extent.java │ │ │ ├── ExtentDirection.kt │ │ │ ├── ExtentManager.java │ │ │ ├── ExtentNotFoundException.java │ │ │ ├── ExtentsModule.java │ │ │ ├── MutableExtent.java │ │ │ ├── RemoteExtent.kt │ │ │ ├── UnionExtent.java │ │ │ └── serializer │ │ │ │ ├── ExtentSerializer.kt │ │ │ │ ├── ExtentSerializers.kt │ │ │ │ └── ExtentTypeSerializer.java │ │ ├── filters │ │ │ ├── Filter.java │ │ │ ├── FilterManager.java │ │ │ ├── Filters.java │ │ │ ├── FiltersModule.java │ │ │ ├── lexer │ │ │ │ ├── FilterLexer.java │ │ │ │ ├── FilterRecursiveDescentParser.java │ │ │ │ ├── Token.java │ │ │ │ └── TokenType.java │ │ │ └── serializer │ │ │ │ ├── FilterSerializer.java │ │ │ │ ├── FilterSerializers.kt │ │ │ │ └── FilterTypeSerializer.java │ │ ├── goal │ │ │ ├── AbstractScoreFilter.java │ │ │ ├── GoalModule.java │ │ │ ├── GoalWinnersStageChangeData.kt │ │ │ ├── LastPlayerAliveWinnerModule.java │ │ │ ├── LastTeamAliveWinnerModule.java │ │ │ ├── NullScoreGoalData.java │ │ │ ├── Score.java │ │ │ ├── ScoreComponent.java │ │ │ └── ScoreFilters.java │ │ ├── includes │ │ │ └── IncludesModule.java │ │ ├── lobby │ │ │ └── LobbyModule.kt │ │ ├── maploading │ │ │ ├── ArchiveCompressionType.java │ │ │ ├── BlurMap.kt │ │ │ ├── BlurMapConfig.kt │ │ │ ├── ChooseNextMapEvent.java │ │ │ ├── LocalArchiver.java │ │ │ ├── MapChoiceStrategy.kt │ │ │ ├── MapLoadException.java │ │ │ ├── MapLoaderModule.kt │ │ │ ├── MapLoaderPreLoadEvent.java │ │ │ └── MapStageChanges.kt │ │ ├── message │ │ │ ├── Message.kt │ │ │ └── MessagesManager.kt │ │ ├── misc │ │ │ ├── JumpPadsModule.kt │ │ │ └── SimpleParticlesModule.kt │ │ ├── spawns │ │ │ ├── DefaultSpawnStrategy.kt │ │ │ ├── Spawn.java │ │ │ ├── SpawnStrategy.kt │ │ │ ├── SpawnsModule.java │ │ │ ├── respawns │ │ │ │ └── StaggeredGroupRespawnsModule.kt │ │ │ └── serializer │ │ │ │ └── SpawnSerializer.java │ │ ├── stages │ │ │ ├── NextStageModule.java │ │ │ ├── PreStageChangeEvent.java │ │ │ ├── Stage.java │ │ │ ├── StageChangeData.kt │ │ │ ├── StageChangeReasons.kt │ │ │ ├── StageChangedEvent.java │ │ │ ├── StageEvent.java │ │ │ ├── StageManager.java │ │ │ ├── StagesCompleteEvent.java │ │ │ └── StagesModule.java │ │ ├── teams │ │ │ ├── BlurTeam.java │ │ │ ├── CollisionRule.java │ │ │ ├── NametagVisibility.java │ │ │ ├── PlayersTeam.java │ │ │ ├── RoundRobinBalancedTeamAssignmentStrategy.kt │ │ │ ├── SpectatorTeam.java │ │ │ ├── StrategyPriority.java │ │ │ ├── TeamAssignmentStrategy.kt │ │ │ ├── TeamManager.java │ │ │ ├── TeamSerializer.java │ │ │ ├── TeamsModule.java │ │ │ └── events │ │ │ │ ├── PlayerChangeTeamEvent.java │ │ │ │ ├── TeamEvent.java │ │ │ │ └── TeamRenameEvent.java │ │ └── vanillafixes │ │ │ └── RevertProjectileVelocity.kt │ │ ├── properties │ │ ├── BlurConfig.java │ │ └── LocationSet.java │ │ ├── serializers │ │ ├── ComponentSerializer.kt │ │ ├── XmlComponentSerializer.kt │ │ └── thirdparty │ │ │ └── VersionSerializer.kt │ │ ├── session │ │ ├── BlurCoreModule.java │ │ ├── BlurPlayer.java │ │ ├── BlurSession.java │ │ ├── RootBlurSession.kt │ │ ├── SessionManager.java │ │ └── WorldBlurSession.java │ │ ├── supervisor │ │ ├── Amendable.java │ │ ├── BlurReportContext.java │ │ ├── SimpleAmendable.java │ │ └── SupervisorContext.java │ │ ├── text │ │ ├── TextFormatter.kt │ │ ├── TextParser.kt │ │ ├── dsl │ │ │ └── ComponentBuilders.kt │ │ └── xml │ │ │ ├── Tags.kt │ │ │ └── XmlParser.kt │ │ └── utils │ │ ├── BukkitExtensions.kt │ │ ├── CollectionsExtensions.kt │ │ ├── KotlinExtensions.kt │ │ ├── TaskBuilder.java │ │ └── relationalops │ │ ├── Relational.java │ │ ├── RelationalOperator.java │ │ ├── RelationalUtils.java │ │ └── Relationals.java └── resources │ └── plugin.yml └── test └── java ├── FilterLexerTest.java └── com └── blurengine └── blur ├── CollectionsExtensionsTest.kt ├── text ├── TextFormatterTest.kt ├── dsl │ └── ComponentBuildersTest.kt └── xml │ └── XmlParserTest.java └── utils ├── CollectionsTests.kt └── relationalops └── RelationalOpsTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven generated files 2 | /target 3 | dependency-reduced-pom.xml 4 | 5 | #Gradle 6 | /bin 7 | /build 8 | /target 9 | .gradle 10 | /out 11 | /*/build 12 | /run 13 | 14 | # Mac OSX generated files 15 | .DS_Store 16 | 17 | # Eclipse generated files 18 | /.classpath 19 | /.project 20 | /.settings 21 | 22 | # Vim generated files 23 | *~ 24 | *.swp 25 | 26 | # XCode 3 and 4 generated files 27 | *.mode1 28 | *.mode1v3 29 | *.mode2v3 30 | *.perspective 31 | *.perspectivev3 32 | *.pbxuser 33 | *.xcworkspace 34 | xcuserdata 35 | *class 36 | 37 | #idea 38 | /.idea 39 | /out 40 | *.iml 41 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/BlurPlayerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur; 18 | 19 | import com.blurengine.blur.session.BlurPlayer; 20 | import com.supaham.commons.bukkit.CommonPlugin; 21 | import com.supaham.commons.bukkit.players.BukkitPlayerManager; 22 | import com.supaham.commons.bukkit.players.PlayerCreationException; 23 | 24 | import org.bukkit.command.CommandSender; 25 | import org.bukkit.entity.Player; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | class BlurPlayerManager extends BukkitPlayerManager { 30 | 31 | public BlurPlayerManager(@Nonnull CommonPlugin plugin) { 32 | super(plugin, BlurPlayer.class); 33 | } 34 | 35 | @Override 36 | protected BlurPlayer createPlayer(Player player) throws PlayerCreationException { 37 | getPlugin().getLog().finer("Creating %s instance for %s ", BlurPlayer.class, player.getName()); 38 | return super.createPlayer(player); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/BlurSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur; 18 | 19 | import com.supaham.commons.bukkit.CommonPlugin; 20 | import com.supaham.commons.bukkit.CommonSettings; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | import pluginbase.config.annotation.NoTypeKey; 28 | 29 | @NoTypeKey 30 | public final class BlurSettings extends CommonSettings { 31 | 32 | private List modules = Arrays.asList(""); 33 | 34 | private BlurSettings() {} 35 | 36 | public BlurSettings(@Nonnull CommonPlugin plugin) { 37 | super(plugin); 38 | } 39 | 40 | public List getModules() { 41 | return modules; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/commands/BlurCommandProviders.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.commands 18 | 19 | import co.aikar.commands.BukkitCommandExecutionContext 20 | import co.aikar.commands.CommandContexts 21 | import com.blurengine.blur.BlurPlugin 22 | import com.blurengine.blur.session.BlurPlayer 23 | import org.bukkit.entity.Player 24 | 25 | class BlurCommandProviders(val plugin: BlurPlugin) { 26 | fun registerAll(context: CommandContexts) { 27 | registerBlurPlayerSenderAwareContext(context) 28 | } 29 | 30 | fun registerBlurPlayerSenderAwareContext(context: CommandContexts) { 31 | context.registerIssuerAwareContext(BlurPlayer::class.java) { _context -> 32 | val player = _context.sender as? Player ?: throw IllegalStateException("Only player command.") 33 | plugin.blur.getPlayer(player) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/components/shared/ExtentGuard.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.components.shared 18 | 19 | import com.blurengine.blur.framework.SharedComponent 20 | import com.blurengine.blur.modules.extents.Extent 21 | import com.blurengine.blur.session.BlurSession 22 | 23 | class ExtentGuard(session: BlurSession) : SharedComponent(session) { 24 | 25 | val extents = ArrayList() 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/countdown/AbstractCountdown.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.countdown; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.framework.AbstractComponent; 22 | import com.blurengine.blur.framework.Module; 23 | import com.blurengine.blur.framework.ticking.Tick; 24 | import com.supaham.commons.bukkit.TickerTask; 25 | 26 | /** 27 | * Represents a countdown object. 28 | */ 29 | public abstract class AbstractCountdown extends AbstractComponent implements Countdown { 30 | 31 | private final int initialTicks; 32 | private final Module module; 33 | private int ticks; 34 | 35 | public AbstractCountdown(Module module, int ticks) { 36 | super(module.getModuleManager()); 37 | this.module = module; 38 | Preconditions.checkArgument(ticks > 0, "ticks cannot be less than 1."); 39 | this.initialTicks = ticks; 40 | } 41 | 42 | public void start() { 43 | module.addSubcomponent(this); 44 | this.ticks = this.initialTicks; 45 | } 46 | 47 | public void stop() { 48 | module.removeSubcomponent(this); 49 | } 50 | 51 | @Tick 52 | public void tick(TickerTask task) { 53 | onTick(); 54 | if (--ticks <= 0) { 55 | onEnd(); 56 | stop(); 57 | } 58 | } 59 | 60 | public int getTicks() { 61 | return ticks; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/countdown/Countdown.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.countdown; 18 | 19 | import com.blurengine.blur.framework.Component; 20 | import com.blurengine.blur.session.BlurPlayer; 21 | 22 | /** 23 | * Represents a countdown object that extends a Tickable object. Since this extends Tickable object, the implementor needs to take into account 24 | * that implementing this class may break any implementations that extend tickable. 25 | */ 26 | public interface Countdown extends Component { 27 | 28 | /** 29 | * Called when the countdown has expired. 30 | */ 31 | void onEnd(); 32 | 33 | /** 34 | * Called when this countdown ticks. This method is until the ticks are zero; when this countdown has finished. 35 | */ 36 | void onTick(); 37 | 38 | void onTick(BlurPlayer player); 39 | 40 | /** 41 | * Called when the countdown has been cancelled. 42 | */ 43 | void onCancel(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/countdown/CountdownWithEXP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.countdown; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.session.BlurPlayer; 21 | 22 | import org.bukkit.entity.Player; 23 | 24 | import java.util.Collection; 25 | import java.util.function.Supplier; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | /** 30 | * Represents a countdown with a {@link BlurPlayer}'s experience bar. That is, {@link Player#getExp()}. 31 | */ 32 | public class CountdownWithEXP extends AbstractCountdown { 33 | 34 | private Supplier> supplier; 35 | private boolean increment; 36 | private float incrementation; 37 | 38 | public CountdownWithEXP(Module module, int ticks, boolean increment) { 39 | this(module, ticks, module::getPlayers, increment); 40 | } 41 | 42 | public CountdownWithEXP(Module module, int ticks, @Nonnull Supplier> supplier, boolean increment) { 43 | super(module, ticks); 44 | this.supplier = supplier; 45 | this.increment = increment; 46 | this.incrementation = 1.0f / ticks; 47 | supplier.get().forEach(p -> p.getPlayer().setExp(this.increment ? 0f : 1f)); 48 | } 49 | 50 | @Override 51 | public void onCancel() { 52 | supplier.get().forEach(p -> p.getPlayer().setExp(this.increment ? 1f : 0f)); 53 | } 54 | 55 | @Override 56 | public void onEnd() { 57 | supplier.get().forEach(p -> p.getPlayer().setExp(this.increment ? 1f : 0f)); 58 | } 59 | 60 | @Override 61 | public void onTick() { 62 | supplier.get().stream().forEach(this::onTick); 63 | } 64 | 65 | @Override 66 | public void onTick(BlurPlayer player) { 67 | player.getPlayer().setExp(Math.min(getTicks() * incrementation, 1f)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/countdown/GlobalGameCountdown.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.countdown; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.session.BlurPlayer; 21 | import com.supaham.commons.bukkit.SingleSound; 22 | 23 | import org.bukkit.Sound; 24 | 25 | /** 26 | * Represents a countdown that sets the player's exp levels as the remaining seconds. A {@link Sound#UI_BUTTON_CLICK} sound is played if 10 or less 27 | * seconds remain. 28 | */ 29 | public class GlobalGameCountdown extends CountdownWithEXP { 30 | 31 | private static final SingleSound CLICK_SOUND = new SingleSound(Sound.UI_BUTTON_CLICK); 32 | 33 | /** 34 | * Constructs a new global game countdown effect. This is equivalent to calling {@link #GlobalGameCountdown(Module, int, boolean)} with 35 | * the boolean as false. 36 | * 37 | * @param module module to own this component 38 | * @param ticks ticks to set 39 | */ 40 | public GlobalGameCountdown(Module module, int ticks) { 41 | this(module, ticks, false); 42 | } 43 | 44 | /** 45 | * Constructs a new global game countdown effect. 46 | * 47 | * @param module module to own this component 48 | * @param ticks ticks to set 49 | * @param increment whether to increment the bar 50 | */ 51 | public GlobalGameCountdown(Module module, int ticks, boolean increment) { 52 | super(module, ticks, increment); 53 | } 54 | 55 | @Override 56 | public void onTick(BlurPlayer player) { 57 | super.onTick(player); 58 | if (getTicks() % 20 == 0 && (getTicks() / 20) <= 10) { 59 | CLICK_SOUND.play(player.getPlayer()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/BlurPlayerDeathEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | 23 | import org.bukkit.Location; 24 | import org.bukkit.event.Event; 25 | import org.bukkit.event.HandlerList; 26 | 27 | import javax.annotation.Nonnull; 28 | import javax.annotation.Nullable; 29 | 30 | /** 31 | * Represents an event that is fired when a {@link BlurPlayer} kills another {@link BlurPlayer}. 32 | */ 33 | public class BlurPlayerDeathEvent extends BlurPlayerEvent { 34 | 35 | private final Location location; 36 | private final Event eventTrigger; 37 | 38 | public BlurPlayerDeathEvent(@Nonnull BlurPlayer victim, @Nullable Event eventTrigger) { 39 | this(victim, victim.getLocation(), eventTrigger); 40 | } 41 | 42 | public BlurPlayerDeathEvent(@Nonnull BlurPlayer victim, @Nonnull Location location, @Nullable Event eventTrigger) { 43 | super(Preconditions.checkNotNull(victim, "victim cannot be null."), victim.getSession()); 44 | this.location = Preconditions.checkNotNull(location, "location cannot be null."); 45 | this.eventTrigger = eventTrigger; 46 | } 47 | 48 | public Location getLocation() { 49 | return location; 50 | } 51 | 52 | @Nullable 53 | public Event getEventTrigger() { 54 | return eventTrigger; 55 | } 56 | 57 | private static final HandlerList handlerList = new HandlerList(); 58 | 59 | @Override 60 | public HandlerList getHandlers() { return handlerList; } 61 | 62 | public static HandlerList getHandlerList() { return handlerList; } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/BlurPlayerEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | import com.blurengine.blur.session.BlurPlayer; 23 | import com.blurengine.blur.session.BlurSession; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | /** 28 | * Represents a {@link BlurPlayer} event. 29 | */ 30 | public abstract class BlurPlayerEvent extends BlurSessionEvent { 31 | 32 | protected final BlurPlayer blurPlayer; 33 | 34 | public BlurPlayerEvent(@Nonnull BlurPlayer blurPlayer) { 35 | this(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), blurPlayer.getSession()); 36 | } 37 | 38 | public BlurPlayerEvent(@Nonnull BlurPlayer blurPlayer, boolean isAsync) { 39 | this(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), blurPlayer.getSession(), isAsync); 40 | } 41 | 42 | public BlurPlayerEvent(BlurPlayer blurPlayer, @Nonnull BlurSession session) { 43 | super(Preconditions.checkNotNull(session, "session cannot be null.")); 44 | this.blurPlayer = blurPlayer; 45 | } 46 | 47 | public BlurPlayerEvent(BlurPlayer blurPlayer, @Nonnull BlurSession session, boolean isAsync) { 48 | super(Preconditions.checkNotNull(session, "session cannot be null."), isAsync); 49 | this.blurPlayer = blurPlayer; 50 | } 51 | 52 | /** 53 | * Returns the primary {@link BlurPlayer} involved in this event. Subclass events will have delegate methods that represent what this primary 54 | * player is. 55 | *

56 | * E.g. {@link PlayerDamagePlayerEvent} returns the damager. {@link PlayerKilledEvent} returns the player that was killed. 57 | * @return primary blur player 58 | */ 59 | public BlurPlayer getBlurPlayer() { 60 | return blurPlayer; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/BlurPlayerRespawnEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | 23 | import org.bukkit.Location; 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | import javax.annotation.Nullable; 28 | 29 | /** 30 | * Represents an event that is fired when a {@link BlurPlayer} is to respawn in the session. 31 | */ 32 | public class BlurPlayerRespawnEvent extends BlurPlayerEvent { 33 | 34 | private Location spawnLocation; 35 | 36 | public BlurPlayerRespawnEvent(@Nonnull BlurPlayer player) { 37 | this(player, null); 38 | } 39 | 40 | public BlurPlayerRespawnEvent(@Nonnull BlurPlayer player, @Nullable Location spawnLocation) { 41 | super(Preconditions.checkNotNull(player, "player cannot be null."), player.getSession()); 42 | this.spawnLocation = spawnLocation; 43 | } 44 | 45 | @Nullable 46 | public Location getSpawnLocation() { 47 | return this.spawnLocation; 48 | } 49 | 50 | public void setSpawnLocation(@Nonnull Location spawnLocation) { 51 | this.spawnLocation = spawnLocation; 52 | } 53 | 54 | private static final HandlerList handlerList = new HandlerList(); 55 | 56 | @Override 57 | public HandlerList getHandlers() { return handlerList; } 58 | 59 | public static HandlerList getHandlerList() { return handlerList; } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerDamagePlayerEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | 23 | import org.bukkit.event.Cancellable; 24 | import org.bukkit.event.Event; 25 | import org.bukkit.event.HandlerList; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | /** 30 | * Represents an event that is fired when a {@link BlurPlayer} causes damage to another {@link BlurPlayer}. 31 | */ 32 | public class PlayerDamagePlayerEvent extends BlurPlayerEvent implements Cancellable { 33 | 34 | private final BlurPlayer victim; 35 | private final Event bukkitEvent; 36 | 37 | public PlayerDamagePlayerEvent(@Nonnull BlurPlayer damager, @Nonnull BlurPlayer victim, @Nonnull Event bukkitEvent) { 38 | super(Preconditions.checkNotNull(damager, "damager"), damager.getSession()); 39 | this.victim = Preconditions.checkNotNull(victim, "victim"); 40 | this.bukkitEvent = Preconditions.checkNotNull(bukkitEvent, "bukkitEvent"); 41 | } 42 | 43 | /** 44 | * Same as {@link #getBlurPlayer()}. 45 | */ 46 | public BlurPlayer getDamager() { 47 | return getBlurPlayer(); 48 | } 49 | 50 | public BlurPlayer getVictim() { 51 | return victim; 52 | } 53 | 54 | @Nonnull 55 | public Event getBukkitEvent() { 56 | return bukkitEvent; 57 | } 58 | 59 | private boolean cancelled; 60 | 61 | @Override 62 | public boolean isCancelled() { return cancelled; } 63 | 64 | @Override 65 | public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } 66 | 67 | private static final HandlerList handlerList = new HandlerList(); 68 | 69 | @Override 70 | public HandlerList getHandlers() { return handlerList; } 71 | 72 | public static HandlerList getHandlerList() { return handlerList; } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerJoinSessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | import com.blurengine.blur.session.BlurSession; 23 | 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | /** 29 | * Represents a {@link BlurPlayerEvent} fired when a {@link BlurPlayer} joins a {@link BlurSession}. Please note that a join may be a rejoin, meaning 30 | * the player was already in the session, but is joining the current session as a result of removal from their last session. 31 | */ 32 | public class PlayerJoinSessionEvent extends BlurPlayerEvent { 33 | 34 | private final boolean rejoin; 35 | 36 | public PlayerJoinSessionEvent(@Nonnull BlurPlayer blurPlayer, @Nonnull BlurSession session, boolean rejoin) { 37 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), session); 38 | this.rejoin = rejoin; 39 | } 40 | 41 | public boolean isRejoin() { 42 | return rejoin; 43 | } 44 | 45 | private static final HandlerList handlerList = new HandlerList(); 46 | 47 | @Override 48 | public HandlerList getHandlers() { return handlerList; } 49 | 50 | public static HandlerList getHandlerList() { return handlerList; } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerKilledEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | 23 | import org.bukkit.Location; 24 | import org.bukkit.event.Event; 25 | import org.bukkit.event.HandlerList; 26 | 27 | import javax.annotation.Nonnull; 28 | import javax.annotation.Nullable; 29 | 30 | /** 31 | * Represents an event that is fired when a {@link BlurPlayer} is killed by another {@link BlurPlayer}. 32 | */ 33 | public class PlayerKilledEvent extends BlurPlayerDeathEvent { 34 | 35 | private final BlurPlayer killer; 36 | 37 | public PlayerKilledEvent(@Nonnull BlurPlayer victim, @Nonnull BlurPlayer killer, @Nullable Event eventTrigger) { 38 | super(victim, eventTrigger); 39 | this.killer = Preconditions.checkNotNull(killer, "killer cannot be null."); 40 | } 41 | 42 | public PlayerKilledEvent(@Nonnull BlurPlayer victim, @Nonnull Location location, @Nonnull BlurPlayer killer, @Nullable Event eventTrigger) { 43 | super(victim, location, eventTrigger); 44 | this.killer = Preconditions.checkNotNull(killer, "killer cannot be null."); 45 | } 46 | 47 | /** 48 | * Same as {@link #getBlurPlayer()}. 49 | */ 50 | public BlurPlayer getVictim() { 51 | return getBlurPlayer(); 52 | } 53 | 54 | public BlurPlayer getKiller() { 55 | return this.killer; 56 | } 57 | 58 | private static final HandlerList handlerList = new HandlerList(); 59 | 60 | @Override 61 | public HandlerList getHandlers() { return handlerList; } 62 | 63 | public static HandlerList getHandlerList() { return handlerList; } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerLeaveSessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | import com.blurengine.blur.session.BlurSession; 23 | 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | import javax.annotation.Nullable; 28 | 29 | /** 30 | * Represents a {@link BlurPlayerEvent} fired before a {@link BlurPlayer} leaves a {@link BlurSession}. 31 | */ 32 | public class PlayerLeaveSessionEvent extends BlurPlayerEvent { 33 | 34 | private BlurSession nextSession; 35 | 36 | public PlayerLeaveSessionEvent(@Nonnull BlurPlayer blurPlayer, @Nonnull BlurSession session, @Nullable BlurSession nextSession) { 37 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), session); 38 | this.nextSession = nextSession; 39 | } 40 | 41 | @Nullable 42 | public BlurSession getNextSession() { 43 | return nextSession; 44 | } 45 | 46 | private static final HandlerList handlerList = new HandlerList(); 47 | 48 | @Override 49 | public HandlerList getHandlers() { return handlerList; } 50 | 51 | public static HandlerList getHandlerList() { return handlerList; } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerMoveBlockEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | 23 | import org.bukkit.Location; 24 | import org.bukkit.event.Cancellable; 25 | import org.bukkit.event.HandlerList; 26 | import org.bukkit.event.player.PlayerMoveEvent; 27 | 28 | import javax.annotation.Nonnull; 29 | 30 | /** 31 | * Represents an event that is called when a {@link BlurPlayer} moves to a different block. This is different as opposed to {@link PlayerMoveEvent} 32 | * which is called whenever a player moves. 33 | */ 34 | public class PlayerMoveBlockEvent extends BlurPlayerEvent implements Cancellable { 35 | 36 | private final PlayerMoveEvent bukkitEvent; 37 | 38 | public PlayerMoveBlockEvent(@Nonnull PlayerMoveEvent bukkitEvent, @Nonnull BlurPlayer blurPlayer) { 39 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), blurPlayer.getSession()); 40 | this.bukkitEvent = Preconditions.checkNotNull(bukkitEvent, "bukkitEvent cannot be null."); 41 | } 42 | 43 | public Location getFrom() { 44 | return bukkitEvent.getFrom(); 45 | } 46 | 47 | public Location getTo() { 48 | return bukkitEvent.getTo(); 49 | } 50 | 51 | public void setTo(Location to) { 52 | bukkitEvent.setTo(to); 53 | } 54 | 55 | @Override 56 | public boolean isCancelled() { return bukkitEvent.isCancelled(); } 57 | 58 | @Override 59 | public void setCancelled(boolean cancelled) { bukkitEvent.setCancelled(cancelled); } 60 | 61 | private static final HandlerList handlerList = new HandlerList(); 62 | 63 | @Override 64 | public HandlerList getHandlers() { return handlerList; } 65 | 66 | public static HandlerList getHandlerList() { return handlerList; } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerPostLeaveSessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | import com.blurengine.blur.session.BlurSession; 23 | 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | /** 29 | * Represents a {@link BlurPlayerEvent} fired after a {@link BlurPlayer} leaves a {@link BlurSession}. 30 | */ 31 | public class PlayerPostLeaveSessionEvent extends BlurPlayerEvent { 32 | 33 | public PlayerPostLeaveSessionEvent(@Nonnull BlurPlayer blurPlayer, @Nonnull BlurSession session) { 34 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), session); 35 | } 36 | 37 | private static final HandlerList handlerList = new HandlerList(); 38 | 39 | @Override 40 | public HandlerList getHandlers() { return handlerList; } 41 | 42 | public static HandlerList getHandlerList() { return handlerList; } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerPreJoinSessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurPlayer; 22 | import com.blurengine.blur.session.BlurSession; 23 | 24 | import org.bukkit.event.Cancellable; 25 | import org.bukkit.event.HandlerList; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | /** 30 | * Represents a {@link BlurPlayerEvent} fired before a {@link BlurPlayer} joins a {@link BlurSession}. 31 | */ 32 | public class PlayerPreJoinSessionEvent extends BlurPlayerEvent implements Cancellable { 33 | 34 | public PlayerPreJoinSessionEvent(@Nonnull BlurPlayer blurPlayer, @Nonnull BlurSession session) { 35 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), session); 36 | } 37 | 38 | private boolean cancelled; 39 | 40 | @Override 41 | public boolean isCancelled() { return cancelled; } 42 | 43 | @Override 44 | public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } 45 | 46 | private static final HandlerList handlerList = new HandlerList(); 47 | 48 | @Override 49 | public HandlerList getHandlers() { return handlerList; } 50 | 51 | public static HandlerList getHandlerList() { return handlerList; } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/players/PlayerSwitchSessionEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.players 18 | 19 | import com.blurengine.blur.session.BlurPlayer 20 | import com.blurengine.blur.session.BlurSession 21 | import org.bukkit.event.Cancellable 22 | import org.bukkit.event.HandlerList 23 | 24 | /** 25 | * [PlayerSwitchSessionEvent] is called when a [BlurPlayer] is switching from one session to another. 26 | * When [RootBlurSession] is involved, the event is never fired. 27 | */ 28 | class PlayerSwitchSessionEvent(blurPlayer: BlurPlayer, var nextSession: BlurSession?) : BlurPlayerEvent(blurPlayer), Cancellable { 29 | val oldSession: BlurSession = blurPlayer.session 30 | 31 | private var cancelled = false 32 | override fun isCancelled() = cancelled 33 | override fun setCancelled(cancel: Boolean) { 34 | cancelled = cancel 35 | } 36 | 37 | override fun getHandlers() = handlerList 38 | 39 | companion object { 40 | @JvmStatic 41 | val handlerList = HandlerList() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/BlurSessionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.BlurSession; 22 | 23 | import org.bukkit.event.Event; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | /** 28 | * Represents a {@link BlurSession} event. 29 | */ 30 | public abstract class BlurSessionEvent extends Event { 31 | 32 | protected final BlurSession blurSession; 33 | 34 | public BlurSessionEvent(@Nonnull BlurSession blurSession) { 35 | Preconditions.checkNotNull(blurSession, "session cannot be null."); 36 | this.blurSession = blurSession; 37 | } 38 | 39 | public BlurSessionEvent(@Nonnull BlurSession blurSession, boolean isAsync) { 40 | super(isAsync); 41 | Preconditions.checkNotNull(blurSession, "session cannot be null."); 42 | this.blurSession = blurSession; 43 | } 44 | 45 | @Nonnull 46 | public BlurSession getSession() { 47 | return blurSession; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/SessionEnableEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class SessionEnableEvent extends BlurSessionEvent { 26 | 27 | public SessionEnableEvent(@Nonnull BlurSession blurSession) { 28 | super(blurSession); 29 | } 30 | 31 | private static final HandlerList handlerList = new HandlerList(); 32 | 33 | @Override 34 | public HandlerList getHandlers() { return handlerList; } 35 | 36 | public static HandlerList getHandlerList() { return handlerList; } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/SessionLoadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * A {@link BlurSessionEvent} called when a {@link BlurSession} is finished loading, always before it reaches its enabled state. 27 | */ 28 | public class SessionLoadEvent extends BlurSessionEvent { 29 | 30 | public SessionLoadEvent(@Nonnull BlurSession blurSession) { 31 | super(blurSession); 32 | } 33 | 34 | private static final HandlerList handlerList = new HandlerList(); 35 | 36 | @Override 37 | public HandlerList getHandlers() { return handlerList; } 38 | 39 | public static HandlerList getHandlerList() { return handlerList; } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/SessionPreLoadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * A {@link BlurSessionEvent} called when a {@link BlurSession} is beginning to load, before the modules are loaded. 27 | */ 28 | public class SessionPreLoadEvent extends BlurSessionEvent { 29 | 30 | public SessionPreLoadEvent(@Nonnull BlurSession blurSession) { 31 | super(blurSession); 32 | } 33 | 34 | private static final HandlerList handlerList = new HandlerList(); 35 | 36 | @Override 37 | public HandlerList getHandlers() { return handlerList; } 38 | 39 | public static HandlerList getHandlerList() { return handlerList; } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/SessionStartEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | public class SessionStartEvent extends BlurSessionEvent { 26 | 27 | public SessionStartEvent(@Nonnull BlurSession blurSession) { 28 | super(blurSession); 29 | } 30 | 31 | private static final HandlerList handlerList = new HandlerList(); 32 | 33 | @Override 34 | public HandlerList getHandlers() { return handlerList; } 35 | 36 | public static HandlerList getHandlerList() { return handlerList; } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/events/session/SessionStopEvent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.events.session 18 | 19 | import com.blurengine.blur.modules.stages.StageChangeData 20 | import com.blurengine.blur.session.BlurSession 21 | 22 | import org.bukkit.event.HandlerList 23 | 24 | class SessionStopEvent(blurSession: BlurSession, val stopData: StageChangeData) : BlurSessionEvent(blurSession) { 25 | override fun getHandlers() = handlerList 26 | 27 | companion object { 28 | @JvmStatic val handlerList = HandlerList() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ComponentState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | /** 22 | * Represents state a {@link Component} can be in. 23 | */ 24 | public enum ComponentState { 25 | 26 | UNLOADED { 27 | @Override 28 | public boolean isAcceptable(@Nonnull ComponentState state) { 29 | return state == LOADED; // UNLOADED must only go to LOADED, no other state. 30 | } 31 | }, LOADED { 32 | @Override 33 | public boolean isAcceptable(@Nonnull ComponentState state) { 34 | return state != LOADED; // LOADED can go to either UNLOADED or ENABLED. 35 | } 36 | }, ENABLED { 37 | @Override 38 | public boolean isAcceptable(@Nonnull ComponentState state) { 39 | return state == LOADED; // ENABLED must only go to LOADED, no other state. 40 | } 41 | }; 42 | 43 | public abstract boolean isAcceptable(@Nonnull ComponentState state); 44 | 45 | public boolean isLoaded() { 46 | return this != UNLOADED; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/InternalModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import com.blurengine.blur.framework.ticking.TickFieldHolder; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Specifies that an internal class is extending Module as a means of convenience and organisability. A case where internal modules are registered 28 | * alongside other modules is {@link TickFieldHolder}. The reason being that the class uses a task, and instead of having to start/stop the task, the 29 | * ModuleManager is already designed for and capable of doing such tasks. This eliminates the need for creating those extra boilerplate methods and 30 | * clutter the ModuleManager with their usages. 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.TYPE) 34 | public @interface InternalModule { 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/InvalidModuleDataException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | /** 20 | * Represents an exception that is thrown when a {@link ModuleData} receives invalid data. 21 | */ 22 | public class InvalidModuleDataException extends Exception { 23 | 24 | public InvalidModuleDataException() { 25 | } 26 | 27 | public InvalidModuleDataException(String message) { 28 | super(message); 29 | } 30 | 31 | public InvalidModuleDataException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public InvalidModuleDataException(Throwable cause) { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ModuleData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import java.util.function.Supplier; 20 | 21 | import kotlin.UninitializedPropertyAccessException; 22 | 23 | /** 24 | * This is an empty interface meant to identify classes that are created by a {@link Module} to store configurable data. 25 | */ 26 | public interface ModuleData { 27 | 28 | Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException; 29 | 30 | default T checkNotNull(T object, String message) throws ModuleParseException { 31 | if (object == null) { 32 | throw new ModuleParseException(message); 33 | } 34 | return object; 35 | } 36 | 37 | default T checkNotNull(T object, String message, Object... args) throws ModuleParseException { 38 | if (object == null) { 39 | throw new ModuleParseException(String.format(message, args)); 40 | } 41 | return object; 42 | } 43 | 44 | default void check(boolean b, String message) throws ModuleParseException { 45 | if (!b) { 46 | throw new ModuleParseException(message); 47 | } 48 | } 49 | 50 | default void check(boolean b, String message, Object... args) throws ModuleParseException { 51 | if (!b) { 52 | throw new ModuleParseException(String.format(message, args)); 53 | } 54 | } 55 | 56 | default T checkNotNullLateInit(Supplier o, String message) throws ModuleParseException { 57 | try { 58 | T t = o.get(); 59 | if (t == null) { 60 | throw new ModuleParseException(message); 61 | } 62 | return t; 63 | } catch (UninitializedPropertyAccessException e) { 64 | throw new ModuleParseException(message); 65 | } 66 | } 67 | 68 | default void checkLateInit(Supplier b, String message) throws ModuleParseException { 69 | try { 70 | if (!b.get()) { 71 | throw new ModuleParseException(message); 72 | } 73 | } catch (UninitializedPropertyAccessException e) { 74 | throw new ModuleParseException(message); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ModuleInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * This annotation is used to reference the {@link ModuleData} class used to process the annotated class. 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.TYPE) 29 | public @interface ModuleInfo { 30 | 31 | /** 32 | * Name of this module. This is mostly used for debugging and such 33 | * 34 | * @return module name 35 | */ 36 | String name(); 37 | 38 | /** 39 | * Serializable {@link ModuleData} class used to serialize and deserialize this module. 40 | * Note: The data class will automatically be registered as a serializable when this module is registered to {@link ModuleManager}. 41 | * 42 | * @return data class 43 | */ 44 | Class dataClass() default ModuleData.class; 45 | 46 | /** 47 | * Module loading type. Defaults to {@link ModuleLoadType#POST_WORLD}. 48 | * 49 | * @return the loading type to allow for this module 50 | */ 51 | ModuleLoadType load() default ModuleLoadType.POST_WORLD; 52 | 53 | /** 54 | * List of {@link Module}s this module depends on, thus loading them before this module. 55 | * 56 | * @return array of module classes 57 | */ 58 | Class[] depends() default {}; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ModuleLoadType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | /** 20 | * Represents the loading type of a {@link Module} to expand its capability. 21 | */ 22 | public enum ModuleLoadType { 23 | 24 | /** 25 | * Allow modules to load prior to the minecraft world being loaded. This is typically used to modify the world generation. 26 | */ 27 | PRE_WORLD, 28 | /** 29 | * Allow the module to load only after the world is loaded. 30 | */ 31 | POST_WORLD; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ModuleNameHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import com.supaham.commons.utils.StringUtils; 20 | 21 | import java.util.Collection; 22 | import java.util.stream.Collectors; 23 | 24 | class ModuleNameHelper { 25 | 26 | public static Collection getSimilarModuleNames(String name) { 27 | return getSimilarModuleNames(name, 3); 28 | } 29 | 30 | public static Collection getSimilarModuleNames(String name, int levenshteinDistance) { 31 | return ModuleLoader.getModuleInfos().stream() 32 | .filter(info -> StringUtils.getLevenshteinDistance(name, info.name()) <= levenshteinDistance) 33 | .map(ModuleInfo::name).collect(Collectors.toList()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ModuleParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | public class ModuleParseException extends Exception { 20 | 21 | public ModuleParseException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/SharedComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | /** 22 | * Represents an interface that is considered a shared component in {@link BlurSession}. 23 | */ 24 | public abstract class SharedComponent extends AbstractComponent { 25 | 26 | public SharedComponent(BlurSession session) { 27 | super(session.getModuleManager()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/WorldModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.session.WorldBlurSession; 22 | 23 | import org.bukkit.World; 24 | 25 | /** 26 | * World Module framework base class. Upon extending this class, you will need to annotate the extension with {@link ModuleInfo} to tell the framework 27 | * how to load this module from the config file. Immediately after implementation, ensure that the class is also registered to the 28 | * {@link ModuleManager} using {@link ModuleLoader#register(Class)}. 29 | * 30 | * @see Module 31 | */ 32 | public class WorldModule extends Module { 33 | 34 | public WorldModule(ModuleManager moduleManager) { 35 | super(moduleManager); 36 | Preconditions.checkState(super.getSession() instanceof WorldBlurSession, "session is not WorldBlurSession."); 37 | } 38 | 39 | @Override 40 | public WorldBlurSession getSession() { 41 | return (WorldBlurSession) super.getSession(); 42 | } 43 | 44 | public World getWorld() { 45 | return getSession().getWorld(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/MetadataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata; 18 | 19 | import java.util.List; 20 | 21 | import javax.annotation.Nonnull; 22 | import javax.annotation.Nullable; 23 | 24 | /** 25 | * Represents an entity that may hold metadata. The implementation should aim to use {@link MetadataStorage} for management of this data. 26 | */ 27 | public interface MetadataHolder { 28 | 29 | boolean hasMetadata(@Nonnull Object object); 30 | 31 | boolean hasMetadata(@Nonnull Class metadataClass); 32 | 33 | T getMetadata(@Nonnull Class metadataClass); 34 | 35 | @Nullable 36 | Object putMetadata(Object object); 37 | 38 | @Nonnull 39 | List removeAll(); 40 | 41 | boolean removeMetadata(T object); 42 | 43 | @Nullable 44 | T removeMetadata(Class metadataClass); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/MetadataStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata; 18 | 19 | import com.google.common.collect.Table; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import javax.annotation.Nonnull; 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * A Metadata storage container interface for {@link MetadataHolder}s. See {@link BasicMetadataStorage} for a basic implementation of all 29 | * functionality. 30 | * @param Type of MetadataHolder to map metadata to 31 | */ 32 | public interface MetadataStorage { 33 | 34 | boolean contains(@Nonnull HOLDER holder); 35 | 36 | boolean contains(@Nonnull HOLDER holder, @Nonnull Object type); 37 | 38 | boolean contains(@Nonnull HOLDER holder, @Nonnull Class typeClass); 39 | 40 | @Nonnull 41 | Table, Object> getAll(); 42 | 43 | @Nonnull 44 | Map, Object> getMap(@Nonnull HOLDER holder); 45 | 46 | @Nonnull 47 | List getList(@Nonnull HOLDER holder); 48 | 49 | @Nullable 50 | T get(@Nonnull HOLDER holder, @Nonnull Class typeClass); 51 | 52 | @Nullable 53 | T put(@Nonnull HOLDER holder, @Nonnull T type); 54 | 55 | @Nonnull 56 | List removeAll(@Nonnull HOLDER holder); 57 | 58 | @Nullable 59 | boolean remove(@Nonnull HOLDER holder, @Nonnull T type); 60 | 61 | @Nullable 62 | T remove(@Nonnull HOLDER holder, @Nonnull Class typeClass); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/auto/MetadataCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata.auto; 18 | 19 | import com.blurengine.blur.framework.metadata.MetadataHolder; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | /** 24 | * Metadata class instance creator. The supplied class may be of any type, but not null. 25 | */ 26 | public interface MetadataCreator { 27 | 28 | @Nonnull 29 | T create(HOLDER holder); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/playerdata/PlayerData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata.playerdata; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | /** 22 | * Interface for more control over custom Player Data Classes. See {@link PlayerAutoMetadataCreator}. 23 | */ 24 | public interface PlayerData { 25 | 26 | /** 27 | * Called after this instance is created and registered into the {@link BlurSession}. This is NOT equivalent to implementing the instance 28 | * initialization block. The difference is this method is called after registration to the {@link BlurSession}. 29 | */ 30 | default void enable() {} 31 | 32 | /** 33 | * Called before this instance is unregistered from the {@link BlurSession}. 34 | */ 35 | default void disable() {} 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/playerdata/PlayerDataCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata.playerdata; 18 | 19 | import com.blurengine.blur.framework.metadata.auto.MetadataCreator; 20 | import com.blurengine.blur.session.BlurPlayer; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | /** 25 | * Player Data class supplier. This does not require that the supplied class be of type {@link PlayerData}. 26 | */ 27 | public interface PlayerDataCreator extends MetadataCreator { 28 | 29 | /** 30 | * Returns a new instance of Player Data for the given {@link BlurPlayer}. 31 | * @param blurPlayer blur player to create data for 32 | * @return new Player Data instance 33 | */ 34 | @Nonnull 35 | T create(BlurPlayer blurPlayer); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/teamdata/TeamData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata.teamdata; 18 | 19 | import com.blurengine.blur.session.BlurSession; 20 | 21 | /** 22 | * Interface for more control over custom Team data Classes. See {@link TeamAutoMetadataCreator}. 23 | */ 24 | public interface TeamData { 25 | 26 | /** 27 | * Called after this instance is created and registered into the {@link BlurSession}. This is NOT equivalent to implementing the instance 28 | * initialization block. The difference is this method is called after registration to the {@link BlurSession}. 29 | */ 30 | default void enable() {} 31 | 32 | /** 33 | * Called before this instance is unregistered from the {@link BlurSession}. 34 | */ 35 | default void disable() {} 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/metadata/teamdata/TeamDataCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.metadata.teamdata; 18 | 19 | import com.blurengine.blur.framework.metadata.auto.MetadataCreator; 20 | import com.blurengine.blur.modules.teams.BlurTeam; 21 | 22 | import javax.annotation.Nonnull; 23 | 24 | /** 25 | * Team data class supplier. This does not require that the supplied class be of type {@link TeamData}. 26 | */ 27 | public interface TeamDataCreator extends MetadataCreator { 28 | 29 | /** 30 | * Returns a new instance of Team data for the given {@link BlurTeam}. 31 | * @param blurTeam blur team to create data for 32 | * @return new team data instance 33 | */ 34 | @Nonnull 35 | T create(BlurTeam blurTeam); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/serializer/ModuleNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.serializer; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | 21 | /** 22 | * Represents a {@link RuntimeException} that is thrown when a {@link Module} could not be found by the given name, accessible through 23 | * {@link #getName()}. 24 | */ 25 | public class ModuleNotFoundException extends RuntimeException { 26 | 27 | private String name; 28 | 29 | public ModuleNotFoundException(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ticking/BAutoInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.ticking; 18 | 19 | /** 20 | * Represents a mutable integer supplier interface. This is used in conjunction with {@link TickField} to create automatically ticking fields for 21 | * convenience and organisability. 22 | */ 23 | public interface BAutoInt { 24 | 25 | /** 26 | * Returns the integer wrapped in this object. 27 | * 28 | * @return integer 29 | */ 30 | int get(); 31 | 32 | /** 33 | * Sets this integer to {@code n}. 34 | * 35 | * @param n integer to set this integer to 36 | * @return the given {@code n} 37 | */ 38 | default int set(int n) { 39 | throw new UnsupportedOperationException(); 40 | } 41 | 42 | /** 43 | * Adds {@code n} to this integer. 44 | * 45 | * @param n integer to add to this integer 46 | * @return the previous value plus the given {@code n} 47 | */ 48 | default int add(int n) { 49 | throw new UnsupportedOperationException(); 50 | } 51 | 52 | /** 53 | * Subtracts {@code n} from this integer. 54 | * 55 | * @param n integer to subtract from this integer 56 | * @return the previous value minus the given {@code n} 57 | */ 58 | default int subtract(int n) { 59 | throw new UnsupportedOperationException(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ticking/Tick.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.ticking; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Represents a method that ticks. 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface Tick { 30 | 31 | long delay() default 0; 32 | long interval() default 1; 33 | boolean ms() default false; 34 | boolean async() default false; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ticking/TickField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.ticking; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Represents a Field annotation that only works if the field is of type {@link BAutoInt}. The purpose of this annotation is to provide a convenient 26 | * way of automatically modifying an integer field. A common use of this is ticking to keep track of the timing of certain events such as how long 27 | * a flag has been carried, or the last time since a kill (where increment = true, and the value is reset.) 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface TickField { 32 | 33 | /** 34 | * The interval of the field ticking. Default is 1. 35 | */ 36 | int value() default 1; 37 | 38 | /** 39 | * Whether to increment or decrement every tick. Default is false. 40 | */ 41 | boolean increment() default false; 42 | 43 | /** 44 | * The initial value of the field. Please keep in mind that this is overridden by the actual field declaration, if it is declared. Default is 0 45 | */ 46 | int initial() default 0; 47 | 48 | /** 49 | * The amount of change, incrementation and decrementation. Default is 1. 50 | *

51 | * TODO Not sure if this is absolutely necessary. (doubting it) 52 | */ 53 | int amount() default 1; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/framework/ticking/TickFieldGenerated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.framework.ticking; 18 | 19 | final class TickFieldGenerated implements BAutoInt, Runnable { 20 | 21 | private static final BAutoInt ZERO_SUPPLIER = () -> 0; 22 | 23 | private final BAutoInt defaultSupplier; 24 | private final TickField data; 25 | 26 | private int nextTick; // next time to update this value 27 | 28 | private int currentValue; // See get() 29 | 30 | public TickFieldGenerated(BAutoInt defaultSupplier, TickField data) { 31 | if (defaultSupplier != null) { 32 | this.defaultSupplier = defaultSupplier; 33 | } else if (data.initial() != 0) { 34 | this.defaultSupplier = data::initial; 35 | } else { // if initial is 0 (default), use static ZERO_SUPPLIER 36 | this.defaultSupplier = ZERO_SUPPLIER; 37 | } 38 | 39 | this.data = data; 40 | this.currentValue = this.defaultSupplier.get(); 41 | } 42 | 43 | // This is what the modules will be receiving. 44 | @Override 45 | public int get() { 46 | return this.currentValue; 47 | } 48 | 49 | @Override 50 | public int set(int n) { 51 | return this.currentValue = n; 52 | } 53 | 54 | @Override 55 | public int add(int n) { 56 | return this.currentValue += n; 57 | } 58 | 59 | @Override 60 | public int subtract(int n) { 61 | return this.currentValue -= n; 62 | } 63 | 64 | @Override 65 | public void run() { 66 | if (--this.nextTick <= 0) { 67 | if (this.data.increment()) { 68 | this.currentValue += this.data.amount(); 69 | } else { 70 | this.currentValue -= this.data.amount(); 71 | if (this.currentValue < 0) { 72 | this.currentValue = this.defaultSupplier.get(); 73 | } 74 | } 75 | this.nextTick = this.data.value(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/inventory/SlotType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.inventory; 18 | 19 | /** 20 | * Represents a type of slot that may be present in an {@link InventoryLayout}. 21 | */ 22 | public interface SlotType { 23 | 24 | SlotType EMPTY = new SlotType() { 25 | @Override 26 | public String getName() { 27 | return "EMPTY"; 28 | } 29 | 30 | @Override 31 | public boolean isClickable() { 32 | return true; 33 | } 34 | }; 35 | 36 | String getName(); 37 | 38 | /** 39 | * Returns whether this slot type is clickable when a human entity clicks on it when their inventory is open. 40 | * 41 | * @return whether this slot type is clickable 42 | */ 43 | default boolean isClickable() { 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/BoundariesModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules; 18 | 19 | import com.blurengine.blur.modules.extents.Extent; 20 | import com.blurengine.blur.framework.Module; 21 | import com.blurengine.blur.framework.ModuleInfo; 22 | import com.blurengine.blur.framework.ModuleManager; 23 | import com.blurengine.blur.framework.ModuleParseException; 24 | import com.blurengine.blur.framework.SerializedModule; 25 | import com.blurengine.blur.modules.BoundariesModule.BoundariesData; 26 | import com.blurengine.blur.framework.ModuleData; 27 | 28 | @ModuleInfo(name = "Boundaries", dataClass = BoundariesData.class) 29 | public class BoundariesModule extends Module { 30 | 31 | private final Extent extent; 32 | 33 | public BoundariesModule(ModuleManager moduleManager, Extent extent) { 34 | super(moduleManager); 35 | this.extent = extent; 36 | } 37 | 38 | // TODO kill the cowards! 39 | 40 | public static final class BoundariesData implements ModuleData { 41 | 42 | @Override 43 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 44 | Extent extent = moduleManager.getExtentManager().getOrCreateExtent(serialized.getAsObject()); 45 | return new BoundariesModule(moduleManager, extent); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/FixedHungerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleData; 21 | import com.blurengine.blur.framework.ModuleInfo; 22 | import com.blurengine.blur.framework.ModuleManager; 23 | import com.blurengine.blur.framework.ModuleParseException; 24 | import com.blurengine.blur.framework.SerializedModule; 25 | import com.blurengine.blur.modules.FixedHungerModule.FixedHungerData; 26 | 27 | import org.bukkit.event.EventHandler; 28 | import org.bukkit.event.entity.FoodLevelChangeEvent; 29 | 30 | @ModuleInfo(name = "FixedHunger", dataClass = FixedHungerData.class) 31 | public class FixedHungerModule extends Module { 32 | 33 | private final int hunger; 34 | 35 | // This constructor is used to read the module's data class, in this case FixedHungerData. 36 | // The constructor is called via reflection from ModuleManager#createModules(Collection). 37 | public FixedHungerModule(ModuleManager moduleManager, FixedHungerData data) { 38 | super(moduleManager); 39 | this.hunger = data.hunger; 40 | } 41 | 42 | @EventHandler public void onFoodLevelChange(FoodLevelChangeEvent event) { 43 | event.setFoodLevel(this.hunger); 44 | } 45 | 46 | public static final class FixedHungerData implements ModuleData { 47 | 48 | private int hunger = 20; // default value of 20. 49 | 50 | @Override public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 51 | serialized.load(this); 52 | return new FixedHungerModule(moduleManager, this); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/RandomCompassTargetModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleInfo; 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.framework.ticking.Tick; 23 | import com.blurengine.blur.session.BlurPlayer; 24 | import com.blurengine.blur.session.BlurSession.Predicates; 25 | 26 | import net.md_5.bungee.api.ChatColor; 27 | import net.md_5.bungee.api.chat.ComponentBuilder; 28 | import net.md_5.bungee.api.chat.TextComponent; 29 | import org.bukkit.Location; 30 | 31 | @ModuleInfo(name = "RandomCompassTarget") 32 | public class RandomCompassTargetModule extends Module { 33 | 34 | private BlurPlayer bait; 35 | 36 | public RandomCompassTargetModule(ModuleManager moduleManager) { 37 | super(moduleManager); 38 | } 39 | 40 | @Tick(interval = 30000, ms = true) 41 | private void updateBait() { 42 | getRandomPlayer(Predicates.ALIVE).ifPresent(p -> { 43 | this.bait = p; 44 | broadcastMessage(new ComponentBuilder(this.bait.getName() + " got baited!").color(ChatColor.YELLOW).create()); 45 | }); 46 | } 47 | 48 | @Tick(interval = 1000, ms = true) 49 | private void updateCompasses() { 50 | Location baitLoc = this.bait.getPlayer().getLocation(); 51 | getPlayers(Predicates.ALIVE).forEach(aliveBP -> aliveBP.getPlayer().setCompassTarget(baitLoc)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointCapturedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | 23 | import org.bukkit.event.HandlerList; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | public class ControlPointCapturedEvent extends BlurSessionEvent { 28 | 29 | private final ControlPoint controlPoint; 30 | 31 | public ControlPointCapturedEvent(@Nonnull ControlPoint controlPoint) { 32 | super(Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null.").getModule().getSession()); 33 | this.controlPoint = controlPoint; 34 | } 35 | 36 | @Nonnull 37 | public ControlPoint getControlPoint() { 38 | return controlPoint; 39 | } 40 | 41 | private static final HandlerList handlerList = new HandlerList(); 42 | 43 | @Override 44 | public HandlerList getHandlers() { return handlerList; } 45 | 46 | public static HandlerList getHandlerList() { return handlerList; } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointEnterEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.players.BlurPlayerEvent; 22 | import com.blurengine.blur.session.BlurPlayer; 23 | 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | public class ControlPointEnterEvent extends BlurPlayerEvent { 29 | 30 | private final ControlPoint controlPoint; 31 | 32 | public ControlPointEnterEvent(BlurPlayer blurPlayer, @Nonnull ControlPoint controlPoint) { 33 | super(blurPlayer); 34 | this.controlPoint = Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null."); 35 | } 36 | 37 | @Nonnull 38 | public ControlPoint getControlPoint() { 39 | return controlPoint; 40 | } 41 | 42 | private static final HandlerList handlerList = new HandlerList(); 43 | 44 | @Override 45 | public HandlerList getHandlers() { return handlerList; } 46 | 47 | public static HandlerList getHandlerList() { return handlerList; } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointExitEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.players.BlurPlayerEvent; 22 | import com.blurengine.blur.session.BlurPlayer; 23 | 24 | import org.bukkit.event.HandlerList; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | public class ControlPointExitEvent extends BlurPlayerEvent { 29 | 30 | private final ControlPoint controlPoint; 31 | 32 | public ControlPointExitEvent(BlurPlayer blurPlayer, @Nonnull ControlPoint controlPoint) { 33 | super(blurPlayer); 34 | this.controlPoint = Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null."); 35 | } 36 | 37 | @Nonnull 38 | public ControlPoint getControlPoint() { 39 | return controlPoint; 40 | } 41 | 42 | private static final HandlerList handlerList = new HandlerList(); 43 | 44 | @Override 45 | public HandlerList getHandlers() { return handlerList; } 46 | 47 | public static HandlerList getHandlerList() { return handlerList; } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointLostEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | import com.blurengine.blur.modules.teams.BlurTeam; 23 | import com.blurengine.blur.session.BlurPlayer; 24 | 25 | import org.bukkit.event.HandlerList; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | public class ControlPointLostEvent extends BlurSessionEvent { 30 | 31 | private final ControlPoint controlPoint; 32 | private final BlurTeam previousOwner; 33 | 34 | public ControlPointLostEvent(@Nonnull ControlPoint controlPoint, @Nonnull BlurTeam previousOwner) { 35 | super(Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null.").getModule().getSession()); 36 | this.controlPoint = controlPoint; 37 | this.previousOwner = Preconditions.checkNotNull(previousOwner, "previousOwner cannot be null."); 38 | } 39 | 40 | @Nonnull 41 | public ControlPoint getControlPoint() { 42 | return controlPoint; 43 | } 44 | 45 | public BlurTeam getPreviousOwner() { 46 | return previousOwner; 47 | } 48 | 49 | private static final HandlerList handlerList = new HandlerList(); 50 | 51 | @Override 52 | public HandlerList getHandlers() { return handlerList; } 53 | 54 | public static HandlerList getHandlerList() { return handlerList; } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointProgressResetEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | 23 | import org.bukkit.event.HandlerList; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | public class ControlPointProgressResetEvent extends BlurSessionEvent { 28 | 29 | private final ControlPoint controlPoint; 30 | 31 | public ControlPointProgressResetEvent(@Nonnull ControlPoint controlPoint) { 32 | super(Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null.").getModule().getSession()); 33 | this.controlPoint = controlPoint; 34 | } 35 | 36 | @Nonnull 37 | public ControlPoint getControlPoint() { 38 | return controlPoint; 39 | } 40 | 41 | private static final HandlerList handlerList = new HandlerList(); 42 | 43 | @Override 44 | public HandlerList getHandlers() { return handlerList; } 45 | 46 | public static HandlerList getHandlerList() { return handlerList; } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/controlpoints/ControlPointProgressTickEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.controlpoints; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | 23 | import org.bukkit.event.HandlerList; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | public class ControlPointProgressTickEvent extends BlurSessionEvent { 28 | 29 | private final ControlPoint controlPoint; 30 | 31 | public ControlPointProgressTickEvent(@Nonnull ControlPoint controlPoint) { 32 | super(Preconditions.checkNotNull(controlPoint, "controlPoint cannot be null.").getModule().getSession()); 33 | this.controlPoint = controlPoint; 34 | } 35 | 36 | @Nonnull 37 | public ControlPoint getControlPoint() { 38 | return controlPoint; 39 | } 40 | 41 | private static final HandlerList handlerList = new HandlerList(); 42 | 43 | @Override 44 | public HandlerList getHandlers() { return handlerList; } 45 | 46 | public static HandlerList getHandlerList() { return handlerList; } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/extents/DirectionalExtent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.extents 18 | 19 | import com.blurengine.blur.modules.extents.ExtentDirection.NullExtentDirection 20 | 21 | interface DirectionalExtent { 22 | /** 23 | * Returns the [ExtentDirection] associated with this Extent. Defaults to [NullExtentDirection]. 24 | * @return non-null extent direction 25 | */ 26 | fun getDirection(): ExtentDirection = NullExtentDirection 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/extents/ExtentNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.extents; 18 | 19 | import java.util.regex.Pattern; 20 | 21 | /** 22 | * Thrown when an extent is not found by a {@link ExtentManager}. 23 | */ 24 | public class ExtentNotFoundException extends RuntimeException { 25 | 26 | public ExtentNotFoundException(String id) { 27 | super("Could not find extent by id '" + id + "'."); 28 | } 29 | 30 | public ExtentNotFoundException(Pattern pattern) { 31 | super("Could not find extent with pattern: " + pattern.pattern()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/extents/ExtentsModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.extents; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleData; 21 | import com.blurengine.blur.framework.ModuleInfo; 22 | import com.blurengine.blur.framework.ModuleManager; 23 | import com.blurengine.blur.framework.ModuleParseException; 24 | import com.blurengine.blur.framework.SerializedModule; 25 | import com.blurengine.blur.modules.extents.ExtentsModule.ExtentsData; 26 | import com.blurengine.blur.modules.extents.serializer.ExtentSerializer; 27 | 28 | import java.util.List; 29 | 30 | import pluginbase.config.annotation.SerializeWith; 31 | 32 | /** 33 | * Represents a {@link Module} that allows for the creation of {@link Extent} and nothing else. Intended for user convenience. 34 | */ 35 | @ModuleInfo(name = "Extents", dataClass = ExtentsData.class) 36 | public class ExtentsModule extends Module { 37 | 38 | private ExtentsModule(ModuleManager moduleManager) { 39 | super(moduleManager); 40 | } 41 | 42 | public static final class ExtentsData implements ModuleData { 43 | 44 | @SerializeWith(ExtentSerializer.class) 45 | private List extents; 46 | 47 | @Override 48 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 49 | if (serialized.getAsObject() instanceof List) { 50 | ExtentSerializer ser = moduleManager.getModuleLoader().getExtentSerializer(); 51 | serialized.getAsList().stream().map(map -> ser.deserialize(map, Extent.class)) 52 | .forEach((s) -> { // This module doesnt care about the deserialized extents, those are registered to the session. 53 | }); 54 | } else { 55 | serialized.load(this); 56 | } 57 | return new ExtentsModule(moduleManager); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/extents/MutableExtent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.extents; 18 | 19 | /** 20 | * Represents a mutable {@link Extent}. Although an empty interface, all mutable access will be provided per {@link Extent} implementation. This class 21 | * serves as no more than a purpose of identifying mutable extents. 22 | */ 23 | public interface MutableExtent extends Extent { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters; 18 | 19 | /** 20 | * Represents a {@link Filter} that is used to represent a condition to control tasks. 21 | */ 22 | public interface Filter { 23 | 24 | FilterResponse test(Object object); 25 | 26 | default Filter inverse() { 27 | return Filters.inverse(this); 28 | } 29 | 30 | default Filter and(Filter other) { 31 | return (object) -> { 32 | FilterResponse first = test(object); 33 | FilterResponse second = other.test(object); 34 | if (first == FilterResponse.ABSTAIN) { 35 | return second; 36 | } else if (second == FilterResponse.ABSTAIN) { 37 | return first; 38 | } else { 39 | return first.isAllowed() && second.isAllowed() ? FilterResponse.ALLOW : FilterResponse.DENY; 40 | } 41 | }; 42 | } 43 | 44 | default Filter or(Filter other) { 45 | return (object) -> { 46 | FilterResponse first = test(object); 47 | if (first == FilterResponse.ALLOW) { 48 | return first; 49 | } 50 | FilterResponse second = other.test(object); 51 | if (second == FilterResponse.ABSTAIN) { 52 | return first; 53 | } 54 | // OR disregards `first` output if it is not ALLOW, and moves directly to whatever `second` is 55 | return second; 56 | }; 57 | } 58 | 59 | enum FilterResponse { 60 | ALLOW, 61 | DENY, 62 | ABSTAIN; 63 | 64 | public static FilterResponse from(boolean allow) { 65 | return allow ? ALLOW : DENY; 66 | } 67 | 68 | public FilterResponse inverse() { 69 | return this == ALLOW ? DENY : this == DENY ? ALLOW : ABSTAIN; 70 | } 71 | 72 | public boolean isAllowed() { 73 | return this == ALLOW || this == ABSTAIN; 74 | } 75 | 76 | public boolean isDenied() { 77 | return this == DENY; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/FilterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.framework.InternalModule; 22 | import com.blurengine.blur.session.BlurSession; 23 | import com.blurengine.blur.framework.Module; 24 | import com.blurengine.blur.framework.ModuleInfo; 25 | import com.blurengine.blur.framework.ModuleLoader; 26 | import com.blurengine.blur.framework.ModuleManager; 27 | 28 | import java.util.Collection; 29 | import java.util.Collections; 30 | import java.util.HashMap; 31 | import java.util.Map; 32 | import java.util.UUID; 33 | 34 | /** 35 | * Represents a {@link Filter} manager. This manager contains all filters registered by a {@link ModuleManager} meaning these same filters can be 36 | * reused in child {@link BlurSession}. 37 | */ 38 | @ModuleInfo(name = "BlurFilterManager") 39 | @InternalModule 40 | public class FilterManager extends Module { 41 | 42 | private Map filters = new HashMap<>(); 43 | 44 | static { 45 | ModuleLoader.register(FiltersModule.class); 46 | } 47 | 48 | public FilterManager(ModuleManager moduleManager) { 49 | super(moduleManager); 50 | } 51 | 52 | public void checkNonExistant(String id) { 53 | Preconditions.checkArgument(id == null || !this.filters.containsKey(id), "filter with id '%s' already exists.", id); 54 | } 55 | 56 | public void addFilter(String id, Filter filter) { 57 | checkNonExistant(id); 58 | if (id == null) { 59 | id = UUID.randomUUID().toString(); 60 | while (this.filters.containsKey(id)) { 61 | id = UUID.randomUUID().toString(); 62 | } 63 | } 64 | this.filters.put(id, filter); 65 | } 66 | 67 | /* ================================ 68 | * >> GETTERS 69 | * ================================ */ 70 | 71 | public Collection getFilters() { 72 | return Collections.unmodifiableCollection(filters.values()); 73 | } 74 | 75 | public Filter getFilterById(String id) { 76 | return this.filters.get(id); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/FiltersModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleInfo; 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.framework.ModuleParseException; 23 | import com.blurengine.blur.framework.SerializedModule; 24 | import com.blurengine.blur.modules.filters.FiltersModule.FiltersData; 25 | import com.blurengine.blur.framework.ModuleData; 26 | import com.blurengine.blur.modules.filters.serializer.FilterSerializer; 27 | 28 | import java.util.List; 29 | 30 | import pluginbase.config.annotation.SerializeWith; 31 | 32 | /** 33 | * Represents a {@link Module} that allows for the creation of {@link Filter} and nothing else. Intended for user convenience. 34 | */ 35 | @ModuleInfo(name = "Filters", dataClass = FiltersData.class) 36 | public class FiltersModule extends Module { 37 | 38 | private FiltersModule(ModuleManager moduleManager) { 39 | super(moduleManager); 40 | } 41 | 42 | public static final class FiltersData implements ModuleData { 43 | 44 | @SerializeWith(FilterSerializer.class) 45 | private List filters; 46 | 47 | @Override 48 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 49 | serialized.load(this); 50 | return new FiltersModule(moduleManager); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/lexer/FilterLexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters.lexer; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | import java.util.List; 22 | import java.util.regex.Matcher; 23 | 24 | /** 25 | * Represents a simple lexer that simply creates tokens matching {@link TokenType}. 26 | */ 27 | public class FilterLexer { 28 | 29 | public Collection lex(String input) { 30 | List result = new ArrayList<>(); 31 | Matcher matcher = TokenType.getFinalPattern().matcher(input); 32 | tokenIteration: 33 | while (matcher.find()) { 34 | for (TokenType tk : TokenType.values()) { 35 | String group = matcher.group(tk.name()); 36 | if (group != null && tk != TokenType.WHITESPACE) { 37 | result.add(tk.toToken(group)); 38 | continue tokenIteration; 39 | } 40 | } 41 | } 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/lexer/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters.lexer; 18 | 19 | /** 20 | * Represents a captured Token from the {@link FilterLexer}. 21 | */ 22 | public class Token { 23 | 24 | private TokenType type; 25 | private String data; 26 | 27 | public Token(TokenType type, String data) { 28 | this.type = type; 29 | this.data = data; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "(" + type + " " + data + ")"; 35 | } 36 | 37 | public TokenType getType() { 38 | return type; 39 | } 40 | 41 | public String getData() { 42 | return data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/lexer/TokenType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters.lexer; 18 | 19 | import com.google.common.base.Function; 20 | 21 | import java.util.regex.Pattern; 22 | 23 | public enum TokenType { 24 | TRUE("true"), 25 | FALSE("false"), 26 | AND("&"), 27 | OR("\\|"), 28 | NOT("!"), 29 | LEFTPAREN("\\("), 30 | RIGHTPAREN("\\)"), 31 | WHITESPACE("\\s+"), 32 | PLAINTEXT("[A-Za-z0-9]+", true); 33 | 34 | private static Pattern FINAL_PATTERN; 35 | 36 | private final String pattern; 37 | private final Function tokenProducer; 38 | 39 | public static Pattern getFinalPattern() { 40 | if (FINAL_PATTERN == null) { 41 | constructPattern(); 42 | } 43 | return FINAL_PATTERN; 44 | } 45 | 46 | private static void constructPattern() { 47 | StringBuffer tokenPatternsBuffer = new StringBuffer(); 48 | for (TokenType tokenType : TokenType.values()) { 49 | tokenPatternsBuffer.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); 50 | } 51 | FINAL_PATTERN = Pattern.compile(tokenPatternsBuffer.substring(1)); 52 | } 53 | 54 | TokenType(String pattern) { 55 | this(pattern, false); 56 | } 57 | 58 | TokenType(String pattern, boolean symbol) { 59 | this.pattern = pattern; 60 | if (symbol) { 61 | this.tokenProducer = (s) -> new Token(this, s); 62 | } else { 63 | this.tokenProducer = (s) -> new Token(this, null); 64 | } 65 | } 66 | 67 | public Token toToken(String s) { 68 | return tokenProducer.apply(s); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/serializer/FilterSerializers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters.serializer 18 | 19 | import com.blurengine.blur.modules.filters.Filter 20 | import com.blurengine.blur.modules.filters.Filters 21 | import org.bukkit.material.MaterialData 22 | import pluginbase.config.serializers.SerializerSet 23 | 24 | public class FilterSerializers { 25 | protected class Material(parent: FilterSerializer) : FilterTypeSerializer(parent) { 26 | override fun deserialize(serialized: Any?, wantedType: Class<*>, serializerSet: SerializerSet): Filter? { 27 | if (serialized == null) return null 28 | 29 | val ser = serializerSet.getClassSerializer(MaterialData::class.java) 30 | val deserialized = ser.deserialize(serialized, MaterialData::class.java, serializerSet)!! 31 | return Filters.material(deserialized) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/filters/serializer/FilterTypeSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.filters.serializer; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.modules.filters.Filter; 22 | import com.blurengine.blur.framework.BlurSerializer; 23 | 24 | import java.util.Map; 25 | 26 | import javax.annotation.Nonnull; 27 | import javax.annotation.Nullable; 28 | 29 | import pluginbase.config.serializers.Serializer; 30 | import pluginbase.config.serializers.SerializerSet; 31 | 32 | /** 33 | * Represents an abstract {@link Serializer} for serializing {@link Filter}s. After creating your serializer, be sure to register it at 34 | * {@link FilterSerializer#registerSerializer(String, Class)}. 35 | */ 36 | public abstract class FilterTypeSerializer implements BlurSerializer { 37 | 38 | private final FilterSerializer parent; 39 | 40 | public FilterTypeSerializer(FilterSerializer parent) { 41 | this.parent = parent; 42 | } 43 | 44 | @Override // serialize(Object) already provided by PB Serializer interface 45 | public Object serialize(T object) { 46 | throw new UnsupportedOperationException("Not implemented yet."); 47 | } 48 | 49 | protected T deserialize(Object object) { 50 | throw new UnsupportedOperationException("Not implemented yet."); 51 | } 52 | 53 | @Nullable 54 | @Override 55 | public Object serialize(@Nullable T object, @Nonnull SerializerSet serializerSet) { 56 | return object == null ? null : serialize(object); 57 | } 58 | 59 | @Nullable 60 | @Override 61 | public T deserialize(@Nullable Object serialized, @Nonnull Class wantedType, @Nonnull SerializerSet serializerSet) { 62 | if (serialized == null) { 63 | return null; 64 | } 65 | deserializedPreHandler(serialized); 66 | return deserialize(serialized); 67 | } 68 | 69 | protected void deserializedPreHandler(Object o) { 70 | Preconditions.checkArgument(o instanceof Map, "serialized object must be a map."); 71 | } 72 | 73 | public FilterSerializer getParentSerializer() { 74 | return parent; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/AbstractScoreFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.modules.filters.Filter; 22 | 23 | import java.util.Map; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | /** 28 | * Represents an abstract {@link Filter} implementation for handling {@link ScoreComponent}. 29 | */ 30 | public abstract class AbstractScoreFilter implements Filter { 31 | 32 | private final GoalModule goalModule; 33 | private Map winnersCache; 34 | 35 | public AbstractScoreFilter(@Nonnull GoalModule goalModule) { 36 | this.goalModule = Preconditions.checkNotNull(goalModule, "goalModule cannot be null."); 37 | } 38 | 39 | protected abstract Map getWinners(Map scorers); 40 | 41 | @Override 42 | public FilterResponse test(Object object) { 43 | if (object instanceof Score) { 44 | Map winners = this.winnersCache; 45 | if (winners == null) { 46 | winners = this.winnersCache = getWinners(goalModule.getScores()); 47 | } 48 | return FilterResponse.from(winners.containsKey(object)); 49 | } 50 | return FilterResponse.ABSTAIN; 51 | } 52 | 53 | public GoalModule getGoalModule() { 54 | return goalModule; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/GoalWinnersStageChangeData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal 18 | 19 | /** 20 | * Represents winners data class for winners in the event of stage changing. 21 | */ 22 | class GoalWinnersStageChangeData(var winners: MutableList = mutableListOf()) 23 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/LastPlayerAliveWinnerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import com.blurengine.blur.events.players.BlurPlayerDeathEvent; 20 | import com.blurengine.blur.framework.ModuleInfo; 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.framework.WorldModule; 23 | import com.blurengine.blur.modules.stages.StageChangeData; 24 | import com.blurengine.blur.modules.stages.StageChangeReasons; 25 | import com.blurengine.blur.session.BlurPlayer; 26 | import com.blurengine.blur.session.BlurSession.Predicates; 27 | 28 | import org.bukkit.event.EventHandler; 29 | 30 | import java.util.Collections; 31 | import java.util.List; 32 | 33 | @ModuleInfo(name = "LastPlayerAliveWinner") 34 | public class LastPlayerAliveWinnerModule extends WorldModule { 35 | 36 | public LastPlayerAliveWinnerModule(ModuleManager moduleManager) { 37 | super(moduleManager); 38 | } 39 | 40 | void check() { 41 | List players = getSession().getPlayers(Predicates.ALIVE); 42 | if (players.size() == 1) { 43 | StageChangeData changeData = new StageChangeData(StageChangeReasons.OBJECTIVE_SUCCESS); 44 | 45 | GoalWinnersStageChangeData winnersData = changeData.getOrCreate(GoalWinnersStageChangeData.class); 46 | winnersData.setWinners(Collections.singletonList(players.iterator().next())); 47 | 48 | getStagesManager().nextStage(changeData); 49 | } 50 | } 51 | 52 | @EventHandler 53 | public void onPlayerDeath(BlurPlayerDeathEvent event) { 54 | if (isSession(event)) { 55 | check(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/LastTeamAliveWinnerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import com.blurengine.blur.events.players.BlurPlayerDeathEvent; 20 | import com.blurengine.blur.framework.ModuleInfo; 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.framework.WorldModule; 23 | import com.blurengine.blur.modules.stages.StageChangeData; 24 | import com.blurengine.blur.modules.stages.StageChangeReasons; 25 | import com.blurengine.blur.modules.teams.BlurTeam; 26 | import com.blurengine.blur.session.BlurPlayer; 27 | import com.blurengine.blur.session.BlurSession.Predicates; 28 | 29 | import org.bukkit.event.EventHandler; 30 | 31 | import java.util.Collections; 32 | import java.util.List; 33 | 34 | @ModuleInfo(name = "LastTeamAliveWinner") 35 | public class LastTeamAliveWinnerModule extends WorldModule { 36 | 37 | public LastTeamAliveWinnerModule(ModuleManager moduleManager) { 38 | super(moduleManager); 39 | } 40 | 41 | void check() { 42 | List players = getSession().getPlayers(Predicates.ALIVE); 43 | BlurTeam blurTeam = getTeamManager().getPlayerTeam(players.get(0)); 44 | boolean allAliveAreSameTeam = getPlayersStream().allMatch(p -> getTeamManager().getPlayerTeam(p).equals(blurTeam)); 45 | if (allAliveAreSameTeam) { 46 | StageChangeData changeData = new StageChangeData(StageChangeReasons.OBJECTIVE_SUCCESS); 47 | 48 | GoalWinnersStageChangeData winnersData = changeData.getOrCreate(GoalWinnersStageChangeData.class); 49 | winnersData.setWinners(Collections.singletonList(blurTeam)); 50 | 51 | getStagesManager().nextStage(changeData); 52 | } 53 | } 54 | 55 | @Override 56 | public void enable() { 57 | super.enable(); 58 | if (getTeamManager().getTeams().size() <= 2) { // Spectator and one other team. 59 | throw new IllegalStateException("LastTeamAliveWinner requires at least two teams to function."); 60 | } 61 | } 62 | 63 | @EventHandler 64 | public void onPlayerDeath(BlurPlayerDeathEvent event) { 65 | if (isSession(event)) { 66 | check(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/NullScoreGoalData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import com.blurengine.blur.modules.goal.GoalModule.ScoreGoalCase; 20 | import com.blurengine.blur.modules.goal.GoalModule.ScoreGoalData; 21 | import com.blurengine.blur.modules.stages.StageChangeReasons; 22 | import com.blurengine.blur.utils.relationalops.Relationals; 23 | 24 | import java.util.Arrays; 25 | 26 | /** 27 | * Represents a null safe instance of {@link ScoreGoalData} that uses {@link Double#MAX_VALUE} as the goal. 28 | */ 29 | public class NullScoreGoalData extends ScoreGoalData { 30 | 31 | public static final NullScoreGoalData INSTANCE = new NullScoreGoalData(); 32 | 33 | private NullScoreGoalData() { 34 | super(null, 0, Arrays.asList(new ScoreGoalCase(StageChangeReasons.OBJECTIVE_SUCCESS, Double.MAX_VALUE, Relationals.number(Double.MAX_VALUE)))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/Score.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.modules.goal.GoalModule.ScoreGoalCase; 22 | import com.blurengine.blur.modules.goal.GoalModule.ScoreGoalData; 23 | import com.blurengine.blur.modules.stages.StageChangeReason; 24 | import com.blurengine.blur.utils.relationalops.RelationalOperator; 25 | 26 | import java.util.Optional; 27 | 28 | import javax.annotation.Nonnull; 29 | 30 | /** 31 | * Represents a wrapper for an Object that can have a score. 32 | *

33 | * This class is package-private as it is mutable and is meant only for trusted access. 34 | */ 35 | class Score { 36 | 37 | private final Object object; 38 | private final ScoreGoalData goalData; 39 | 40 | private double score; 41 | 42 | public Score(@Nonnull Object object, @Nonnull ScoreGoalData goalData) { 43 | this.object = Preconditions.checkNotNull(object, "object cannot be null."); 44 | this.goalData = Preconditions.checkNotNull(goalData, "goalData cannot be null."); 45 | reset(); // Set initial 46 | } 47 | 48 | public Optional checkGoalMet() { 49 | for (ScoreGoalCase _case : this.goalData.getCases()) { 50 | if (_case.getGoalRelational().apply(getScore(), RelationalOperator.EQUAL)) { 51 | return Optional.of(_case.getResult()); 52 | } 53 | } 54 | return Optional.empty(); 55 | } 56 | 57 | public double reset() { 58 | return this.score = getInitial(); 59 | } 60 | 61 | public void set(double score) { 62 | this.score = score; 63 | } 64 | 65 | public double add(double score) { 66 | return this.score += score; 67 | } 68 | 69 | public double subtract(double score) { 70 | return this.score -= score; 71 | } 72 | 73 | public double increment() { 74 | return ++this.score; 75 | } 76 | 77 | public double decrement() { 78 | return --this.score; 79 | } 80 | 81 | public double getScore() { 82 | return score; 83 | } 84 | 85 | public Object getObject() { 86 | return object; 87 | } 88 | 89 | public double getInitial() { 90 | return this.goalData.getInitialScore(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/goal/ScoreFilters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.goal; 18 | 19 | import java.util.Map; 20 | import java.util.Map.Entry; 21 | import java.util.stream.Collectors; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * Represents {@link AbstractScoreFilter} implementations. 27 | */ 28 | public class ScoreFilters { 29 | 30 | public static class LowestScoreFilter extends AbstractScoreFilter { 31 | 32 | public LowestScoreFilter(@Nonnull GoalModule goalModule) { 33 | super(goalModule); 34 | } 35 | 36 | @Override 37 | protected Map getWinners(Map scores) { 38 | double highestScore = scores.values().stream().mapToDouble(i -> i).min().orElse(-1); 39 | return scores.entrySet().stream().filter(e -> e.getValue() == highestScore) 40 | .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); 41 | } 42 | } 43 | 44 | public static class HighestScoreFilter extends AbstractScoreFilter { 45 | 46 | public HighestScoreFilter(@Nonnull GoalModule goalModule) { 47 | super(goalModule); 48 | } 49 | 50 | @Override 51 | protected Map getWinners(Map scores) { 52 | double highestScore = scores.values().stream().mapToDouble(i -> i).max().orElse(-1); 53 | return scores.entrySet().stream().filter(e -> e.getValue() == highestScore) 54 | .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/ArchiveCompressionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading; 18 | 19 | public enum ArchiveCompressionType { 20 | 21 | NONE, ZIP 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/BlurMap.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading 18 | 19 | import com.blurengine.blur.framework.ModuleLoader 20 | import com.google.common.base.Objects 21 | import com.supaham.commons.bukkit.utils.SerializationUtils 22 | import pluginbase.config.datasource.yaml.YamlDataSource 23 | import java.io.File 24 | import java.io.IOException 25 | 26 | /** 27 | * Represents a Map that consists of a [File] representing a [com.blurengine.blur.properties.BlurConfig]. 28 | */ 29 | class BlurMap { 30 | lateinit var mapLoader: MapLoaderModule 31 | private set 32 | lateinit var mapDirectory: File 33 | private set 34 | lateinit var mapFile: File 35 | private set 36 | val config: BlurMapConfig by lazy { 37 | val yaml: YamlDataSource 38 | try { 39 | if (!mapFile.exists()) { 40 | throw MapLoadException(MAP_FILE_NAME + " is missing in " + mapFile.toString()) 41 | } 42 | yaml = SerializationUtils.yaml(mapFile).build() 43 | } catch (e: IOException) { 44 | throw MapLoadException("Failed to read " + MAP_FILE_NAME, e) 45 | } 46 | 47 | val config = BlurMapConfig() 48 | SerializationUtils.loadOrCreateProperties(mapLoader.logger, yaml, config, null, ModuleLoader.getStaticSerializerSetBuilder().build()) 49 | require(config.map != null) { "map section must be defined in $id" } 50 | return@lazy config 51 | } 52 | 53 | val id: String 54 | 55 | val name: String get() = config.map!!.name ?: id 56 | 57 | companion object { 58 | val MAP_FILE_NAME = "blur.yml" 59 | } 60 | 61 | constructor(mapLoader: MapLoaderModule, mapDirectory: File) : this(mapLoader, mapDirectory, File(mapDirectory, MAP_FILE_NAME)) 62 | 63 | constructor(mapLoader: MapLoaderModule, mapDirectory: File, mapFile: File) { 64 | this.mapLoader = mapLoader 65 | this.mapDirectory = mapDirectory 66 | this.mapFile = mapFile 67 | require(mapFile.exists()) { "${mapFile.path} does not exist." } 68 | this.id = mapDirectory.name 69 | } 70 | 71 | override fun equals(other: Any?): Boolean { 72 | if (other !is BlurMap) return false 73 | return this.id == other.id && this.mapFile == other.mapFile 74 | } 75 | 76 | override fun hashCode(): Int { 77 | return Objects.hashCode(this.id, this.mapFile) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/ChooseNextMapEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading; 18 | 19 | import org.bukkit.event.Event; 20 | import org.bukkit.event.HandlerList; 21 | 22 | import java.io.File; 23 | 24 | public class ChooseNextMapEvent extends Event { 25 | 26 | private final MapLoaderModule mapLoader; 27 | private BlurMap nextMap; 28 | 29 | public ChooseNextMapEvent(MapLoaderModule mapLoader, BlurMap nextMap) { 30 | this.mapLoader = mapLoader; 31 | this.nextMap = nextMap; 32 | } 33 | 34 | public MapLoaderModule getMapLoader() { 35 | return mapLoader; 36 | } 37 | 38 | public BlurMap getNextMap() { 39 | return nextMap; 40 | } 41 | 42 | public void setNextMap(BlurMap nextMap) { 43 | this.nextMap = nextMap; 44 | } 45 | 46 | private static final HandlerList handlerList = new HandlerList(); 47 | 48 | @Override 49 | public HandlerList getHandlers() { return handlerList; } 50 | 51 | public static HandlerList getHandlerList() { return handlerList; } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/MapChoiceStrategy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading 18 | 19 | interface MapChoiceStrategy { 20 | fun getAvailableMaps(): List 21 | 22 | fun getMap(): BlurMap 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/MapLoadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading; 18 | 19 | /** 20 | * Represents an {@link Exception} that is thrown when a map fails to load from {@link MapLoaderModule}. 21 | */ 22 | public class MapLoadException extends Exception { 23 | 24 | public MapLoadException(String message) { 25 | super(message); 26 | } 27 | 28 | public MapLoadException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/MapLoaderPreLoadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading; 18 | 19 | import org.bukkit.event.Cancellable; 20 | import org.bukkit.event.Event; 21 | import org.bukkit.event.HandlerList; 22 | 23 | public class MapLoaderPreLoadEvent extends Event implements Cancellable { 24 | 25 | private final MapLoaderModule module; 26 | private boolean cancelled; 27 | 28 | public MapLoaderPreLoadEvent(MapLoaderModule module) { 29 | this.module = module; 30 | } 31 | 32 | public MapLoaderModule getModule() { 33 | return module; 34 | } 35 | 36 | @Override 37 | public boolean isCancelled() { 38 | return cancelled; 39 | } 40 | 41 | @Override 42 | public void setCancelled(boolean cancelled) { 43 | this.cancelled = cancelled; 44 | } 45 | 46 | private static final HandlerList handlerList = new HandlerList(); 47 | 48 | @Override 49 | public HandlerList getHandlers() { return handlerList; } 50 | 51 | public static HandlerList getHandlerList() { return handlerList; } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/maploading/MapStageChanges.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.maploading 18 | 19 | import com.blurengine.blur.modules.stages.StageChangeReason 20 | 21 | enum class MapStageChanges: StageChangeReason { 22 | MAP_LOAD_FAILURE 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/message/Message.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.message 18 | 19 | import com.blurengine.blur.session.BlurPlayer 20 | import net.md_5.bungee.api.chat.BaseComponent 21 | 22 | interface Message { 23 | val messageNode: String 24 | val component: BaseComponent 25 | 26 | fun send(blurPlayer: BlurPlayer, vararg args: Any?) 27 | } 28 | 29 | abstract class AbstractMessage(override val messageNode: String, override val component: BaseComponent) : Message 30 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/misc/JumpPadsModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.misc 18 | 19 | import com.blurengine.blur.events.players.PlayerMoveBlockEvent 20 | import com.blurengine.blur.framework.Module 21 | import com.blurengine.blur.framework.ModuleData 22 | import com.blurengine.blur.framework.ModuleInfo 23 | import com.blurengine.blur.framework.ModuleManager 24 | import com.blurengine.blur.framework.SerializedModule 25 | import com.blurengine.blur.modules.extents.Extent 26 | import com.blurengine.blur.modules.misc.JumpPadsModule.JumpPadsModuleData 27 | import com.blurengine.blur.utils.withMultiply 28 | import com.supaham.commons.bukkit.utils.RelativeVector 29 | import org.bukkit.event.EventHandler 30 | import pluginbase.config.annotation.Name 31 | 32 | @ModuleInfo(name = "JumpPads", dataClass = JumpPadsModuleData::class) 33 | class JumpPadsModule(moduleManager: ModuleManager, val data: JumpPadsModuleData) : Module(moduleManager) { 34 | 35 | @EventHandler 36 | fun onPlayerMoveBlock(event: PlayerMoveBlockEvent) { 37 | for (jumpPad in data.jumpPads) { 38 | if (jumpPad.extent.contains(event.blurPlayer)) { 39 | val dir = event.blurPlayer.player.location.direction 40 | val jumpPadData = jumpPad.velocity ?: data.velocity!! 41 | event.blurPlayer.player.velocity = jumpPadData.withMultiply(dir) 42 | } 43 | } 44 | } 45 | 46 | class JumpPadsModuleData : CommonJumpPadData(), ModuleData { 47 | @Name("jump-pads") 48 | var jumpPads = ArrayList() 49 | 50 | override fun parse(moduleManager: ModuleManager, serialized: SerializedModule): Module { 51 | // Defaults of CommonJumpPadData 52 | this.velocity = RelativeVector(1.0, 1.4, 1.0, true, false, true) // 1,~1.4,1 53 | 54 | serialized.load(this) 55 | 56 | for (jumpPad in jumpPads) { 57 | checkNotNullLateInit({ jumpPad.extent }, "JumpPad location must be set") 58 | } 59 | return JumpPadsModule(moduleManager, this) 60 | } 61 | } 62 | 63 | open class CommonJumpPadData { 64 | @Name("velocity") 65 | var velocity: RelativeVector? = null 66 | } 67 | 68 | class JumpPadEntry : CommonJumpPadData() { 69 | lateinit var extent: Extent 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/spawns/DefaultSpawnStrategy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.spawns 18 | 19 | import org.bukkit.entity.Entity 20 | import java.util.function.Supplier 21 | 22 | 23 | class DefaultSpawnStrategy(override val spawns: Supplier>, val defaultSpawn: Spawn) : SpawnStrategy { 24 | override fun getSpawn(entity: Entity): Spawn? { 25 | val spawns = spawns.get() 26 | return spawns.firstOrNull { s -> s.filter.test(entity).isAllowed } ?: defaultSpawn 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/spawns/Spawn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.spawns; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.modules.extents.BlockExtent; 22 | import com.blurengine.blur.modules.extents.Extent; 23 | import com.blurengine.blur.modules.filters.Filter; 24 | import com.blurengine.blur.modules.filters.Filters; 25 | 26 | import javax.annotation.Nonnull; 27 | 28 | /** 29 | * Represents a spawnpoint used by {@link SpawnsModule}. 30 | */ 31 | public class Spawn { 32 | 33 | public static final Spawn ZERO = new Spawn(BlockExtent.ZERO); 34 | 35 | private final Extent extent; 36 | private final Filter filter; 37 | 38 | public Spawn(@Nonnull Extent extent) { 39 | this(extent, Filters.ALWAYS_ALLOW); 40 | } 41 | 42 | public Spawn(@Nonnull Extent extent, @Nonnull Filter filter) { 43 | this.extent = Preconditions.checkNotNull(extent, "extent cannot be null."); 44 | this.filter = Preconditions.checkNotNull(filter, "filter cannot be null."); 45 | } 46 | 47 | public Extent getExtent() { 48 | return extent; 49 | } 50 | 51 | 52 | public Filter getFilter() { 53 | return filter; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/spawns/SpawnStrategy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.spawns 18 | 19 | import org.bukkit.entity.Entity 20 | import java.util.function.Supplier 21 | 22 | /** 23 | * Represents a strategical class that outputs a [Spawn] for a given [Entity]. 24 | * 25 | * [SpawnStrategy] are registered in [SpawnsModule] for gameplay feature. 26 | */ 27 | interface SpawnStrategy { 28 | val spawns: Supplier> 29 | 30 | fun getSpawn(entity: Entity): Spawn? 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/NextStageModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleInfo; 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.framework.ModuleParseException; 23 | import com.blurengine.blur.framework.SerializedModule; 24 | import com.blurengine.blur.framework.ModuleData; 25 | import com.blurengine.blur.modules.stages.NextStageModule.NextStageModuleData; 26 | 27 | import java.time.Duration; 28 | 29 | @ModuleInfo(name = "NextStage", dataClass = NextStageModuleData.class) 30 | public class NextStageModule extends Module { 31 | 32 | public NextStageModule(ModuleManager moduleManager, Duration waitTime) { 33 | super(moduleManager); 34 | } 35 | 36 | public static final class NextStageModuleData implements ModuleData { 37 | 38 | private Duration waitTime; 39 | 40 | @Override 41 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 42 | if (serialized.getAsObject() instanceof String) { 43 | 44 | } else { 45 | serialized.load(this); 46 | } 47 | return new NextStageModule(moduleManager, waitTime); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/PreStageChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.bukkit.event.Cancellable; 22 | import org.bukkit.event.HandlerList; 23 | 24 | import javax.annotation.Nonnull; 25 | import javax.annotation.Nullable; 26 | 27 | public class PreStageChangeEvent extends StageEvent implements Cancellable { 28 | 29 | private final Stage newStage; 30 | private final StageChangeData changeData; 31 | 32 | public PreStageChangeEvent(@Nonnull StageManager manager, @Nonnull StageChangeData changeData, @Nullable Stage newStage) { 33 | super(Preconditions.checkNotNull(manager, "manager cannot be null.")); 34 | this.changeData = Preconditions.checkNotNull(changeData, "reason cannot be null."); 35 | this.newStage = newStage; 36 | if (this.newStage != null) { 37 | Preconditions.checkArgument(manager.equals(newStage.getManager()), "newStage manager is not the same as the given manager."); 38 | } 39 | } 40 | 41 | public StageChangeData getChangeData() { 42 | return changeData; 43 | } 44 | 45 | private boolean cancelled; 46 | 47 | @Override 48 | public boolean isCancelled() { return cancelled; } 49 | 50 | @Override 51 | public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } 52 | 53 | private static final HandlerList handlerList = new HandlerList(); 54 | 55 | @Override 56 | public HandlerList getHandlers() { return handlerList; } 57 | 58 | public static HandlerList getHandlerList() { return handlerList; } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/Stage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.framework.ModuleManager; 22 | import com.blurengine.blur.session.BlurSession; 23 | import com.blurengine.blur.framework.Module; 24 | 25 | import java.util.Collection; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Represents a Stage of a {@link ModuleManager}, typically representing a {@link BlurSession} stage. Meant for games that provide multiple stages. 31 | */ 32 | public final class Stage { 33 | 34 | private final StageManager manager; 35 | private final String name; 36 | private final List modules; 37 | 38 | public Stage(StageManager manager, String name, List modules) { 39 | this.manager = Preconditions.checkNotNull(manager, "manager cannot be null."); 40 | this.name = Preconditions.checkNotNull(name, "name cannot be null."); 41 | this.modules = Preconditions.checkNotNull(modules, "modules cannot be null."); 42 | } 43 | 44 | public StageManager getManager() { 45 | return manager; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public Collection getModules() { 53 | return Collections.unmodifiableCollection(this.modules); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StageChangeData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages 18 | 19 | import java.util.Collections 20 | import javax.annotation.Nonnull 21 | 22 | class StageChangeData(val reason: StageChangeReason) { 23 | private val _customData = HashMap, Any>() 24 | /** 25 | * Unmodifiable collection 26 | */ 27 | val customData: Collection = Collections.unmodifiableCollection(_customData.values) 28 | 29 | operator fun get(dataClass: Class) = _customData[dataClass] as? T 30 | 31 | @Nonnull 32 | fun getOrCreate(dataClass: Class): T { 33 | var data = get(dataClass) 34 | if (data == null) { 35 | data = dataClass.newInstance()!! 36 | put(data) 37 | } 38 | return data 39 | } 40 | 41 | inline fun get() = get(T::class.java) 42 | 43 | @Nonnull 44 | inline fun getOrCreate() = getOrCreate(T::class.java) 45 | 46 | fun put(data: Any) { 47 | require(data.javaClass !in _customData) { "${data.javaClass} is already registered." } 48 | _customData[data.javaClass] = data 49 | } 50 | 51 | fun remove(data: Any): Boolean { 52 | return _customData.remove(data.javaClass) == data 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StageChangeReasons.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages 18 | 19 | import java.util.Objects 20 | 21 | interface StageChangeReason { 22 | val name: String 23 | 24 | } 25 | 26 | abstract class AbstractStageChangeReason : StageChangeReason { 27 | override fun equals(other: Any?): Boolean { 28 | return other is StageChangeReason && other.name == this.name 29 | } 30 | override fun toString(): String { 31 | return name 32 | } 33 | 34 | override fun hashCode(): Int { 35 | return Objects.hash(name) 36 | } 37 | } 38 | 39 | /** 40 | * An enumeration of reasons as to why a [StageManager] would change its stage. 41 | */ 42 | enum class StageChangeReasons : StageChangeReason { 43 | /** 44 | * [Stage] has changed due to the [StageManager] loading up. 45 | */ 46 | STAGES_START, 47 | /** 48 | * [Stage] has changed due to the objective being accomplished by a player/team. 49 | */ 50 | OBJECTIVE_SUCCESS, 51 | /** 52 | * [Stage] has changed due to the objective being failed. 53 | * 54 | * 55 | * **Not to be confused with [TIME_LIMIT], which states time running out.** 56 | * 57 | * @see TIME_LIMIT 58 | */ 59 | OBJECTIVE_FAILED, 60 | /** 61 | * [Stage] has changed due to a time limit running out. 62 | */ 63 | TIME_LIMIT, 64 | /** 65 | * [Stage] has changed due to a module such as [NextStageModule] being loaded. 66 | */ 67 | MODULE_TRIGGERED, 68 | /** 69 | * Stage changing because of shutdown. 70 | */ 71 | SHUTDOWN, 72 | /** 73 | * [Stage] has changed due to an unforeseen event. 74 | */ 75 | UNKNOWN 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StageChangedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | import javax.annotation.Nullable; 25 | 26 | /** 27 | * Called when a {@link StageManager} has changed its current stage. Keep in mind, when all stages have been completed {@link StagesCompleteEvent} 28 | * will be called alongside this event. This is done for user convenience so please use it where appropriate. 29 | * 30 | * @see StagesCompleteEvent 31 | */ 32 | public class StageChangedEvent extends StageEvent { 33 | 34 | private final Stage newStage; 35 | private final Stage oldStage; 36 | private final StageChangeData changeData; 37 | 38 | public StageChangedEvent(@Nonnull StageChangeData changeData, @Nonnull Stage newStage, @Nullable Stage oldStage) { 39 | super(Preconditions.checkNotNull(newStage, "newStage cannot be null.").getManager()); 40 | this.changeData = Preconditions.checkNotNull(changeData, "reason cannot be null."); 41 | this.newStage = newStage; 42 | this.oldStage = oldStage; 43 | if (this.oldStage != null) { 44 | Preconditions.checkArgument(this.oldStage.getManager().equals(newStage.getManager()), 45 | "newStage manager is not the same as the oldStage manager."); 46 | } 47 | } 48 | 49 | @Nonnull 50 | public Stage getNewStage() { 51 | return newStage; 52 | } 53 | 54 | @Nullable 55 | public Stage getOldStage() { 56 | return oldStage; 57 | } 58 | 59 | @Nonnull 60 | public StageChangeData getChangeData() { 61 | return changeData; 62 | } 63 | 64 | private static final HandlerList handlerList = new HandlerList(); 65 | 66 | @Override 67 | public HandlerList getHandlers() { return handlerList; } 68 | 69 | public static HandlerList getHandlerList() { return handlerList; } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StageEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * Represents a {@link BlurSessionEvent} that involves {@link StageManager}. 27 | */ 28 | public abstract class StageEvent extends BlurSessionEvent { 29 | 30 | private final StageManager stageManager; 31 | 32 | public StageEvent(@Nonnull StageManager stageManager) { 33 | super(Preconditions.checkNotNull(stageManager, "stageManager cannot be null.").getSession()); 34 | this.stageManager = stageManager; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StagesCompleteEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.bukkit.event.HandlerList; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * Called when a {@link StageManager} reaches the end of its stages according to {@link StageManager#nextStage(StageChangeReason)}. Keep in mind 27 | * {@link StageChangedEvent} will still be called. 28 | * 29 | * @see StageChangedEvent 30 | */ 31 | public class StagesCompleteEvent extends StageEvent { 32 | 33 | private final StageChangeData changeData; 34 | private final Stage lastStage; 35 | 36 | public StagesCompleteEvent(@Nonnull StageChangeData changeData, @Nonnull Stage lastStage) { 37 | super(Preconditions.checkNotNull(lastStage, "lastStage cannot be null.").getManager()); 38 | this.changeData = Preconditions.checkNotNull(changeData, "changeData cannot be null."); 39 | this.lastStage = lastStage; 40 | } 41 | 42 | public StageChangeData getChangeData() { 43 | return changeData; 44 | } 45 | 46 | public Stage getLastStage() { 47 | return lastStage; 48 | } 49 | 50 | private static final HandlerList handlerList = new HandlerList(); 51 | 52 | @Override 53 | public HandlerList getHandlers() { return handlerList; } 54 | 55 | public static HandlerList getHandlerList() { return handlerList; } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/stages/StagesModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.stages; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleData; 21 | import com.blurengine.blur.framework.ModuleInfo; 22 | import com.blurengine.blur.framework.ModuleManager; 23 | import com.blurengine.blur.framework.ModuleParseException; 24 | import com.blurengine.blur.framework.SerializedModule; 25 | import com.blurengine.blur.framework.serializer.ModuleSerializer; 26 | import com.blurengine.blur.modules.stages.StagesModule.StagesData; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | import pluginbase.config.annotation.NoTypeKey; 32 | import pluginbase.config.annotation.SerializeWith; 33 | 34 | @ModuleInfo(name = "Stages", dataClass = StagesData.class) 35 | public class StagesModule extends Module { 36 | 37 | static { 38 | 39 | } 40 | 41 | public StagesModule(ModuleManager moduleManager, List stages) throws ModuleParseException { 42 | super(moduleManager); 43 | StageManager mgr = moduleManager.getStageManager(); 44 | stages.stream().map(data -> new Stage(mgr, data.name, data.modules)).forEach(mgr::addStage); 45 | } 46 | 47 | public static final class StagesData implements ModuleData { 48 | 49 | private final List stageDatas = new ArrayList<>(0); 50 | 51 | @Override 52 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 53 | serialized.load(this); 54 | return new StagesModule(moduleManager, stageDatas); 55 | } 56 | } 57 | 58 | @NoTypeKey 59 | private static final class StageData { 60 | 61 | private String name; 62 | @SerializeWith(ModuleSerializer.class) 63 | private List modules; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/CollisionRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams; 18 | 19 | import org.bukkit.scoreboard.Team.OptionStatus; 20 | 21 | /** 22 | * Represents a collision rules for handling team entity collisions. 23 | */ 24 | public enum CollisionRule { 25 | EVERYONE(OptionStatus.ALWAYS), NOONE(OptionStatus.NEVER), ALLIES(OptionStatus.FOR_OTHER_TEAMS), 26 | ENEMIES(OptionStatus.FOR_OWN_TEAM); 27 | private final OptionStatus bukkit; 28 | 29 | CollisionRule(OptionStatus bukkit) { 30 | this.bukkit = bukkit; 31 | } 32 | 33 | public OptionStatus getBukkit() { 34 | return bukkit; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/NametagVisibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams; 18 | 19 | import org.bukkit.scoreboard.Team.OptionStatus; 20 | 21 | /** 22 | * Represents a state of visibility a team's nametags can be. 23 | */ 24 | public enum NametagVisibility { 25 | EVERYONE(OptionStatus.ALWAYS), NOONE(OptionStatus.NEVER), ALLIES(OptionStatus.FOR_OTHER_TEAMS), 26 | ENEMIES(OptionStatus.FOR_OWN_TEAM); 27 | private final OptionStatus bukkit; 28 | 29 | NametagVisibility(OptionStatus bukkit) { 30 | this.bukkit = bukkit; 31 | } 32 | 33 | public OptionStatus getBukkit() { 34 | return bukkit; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/PlayersTeam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams; 18 | 19 | /** 20 | * Represents a {@link BlurTeam} designed for spectating players. 21 | */ 22 | public class PlayersTeam extends BlurTeam { 23 | 24 | public static final String TEAM_ID = "players"; 25 | 26 | public PlayersTeam(TeamManager manager) { 27 | super(manager, BlurTeam.builder().id(TEAM_ID).name("Players").max(9001).maxOverfill(9001)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/RoundRobinBalancedTeamAssignmentStrategy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams 18 | 19 | import com.blurengine.blur.session.BlurPlayer 20 | import com.blurengine.blur.utils.allMinBy 21 | import java.util.function.Supplier 22 | 23 | class RoundRobinBalancedTeamAssignmentStrategy(override val teams: Supplier>) : TeamAssignmentStrategy { 24 | override fun getTeam(blurPlayer: BlurPlayer): BlurTeam? { 25 | val teams = teams.get() 26 | val minPlayerTeams = teams 27 | .map { it to it.playerCount } 28 | .allMinBy { (_, playerCount) -> playerCount } 29 | .map { it.first } 30 | return minPlayerTeams.first() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/SpectatorTeam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams; 18 | 19 | import net.md_5.bungee.api.ChatColor; 20 | import org.bukkit.Color; 21 | 22 | /** 23 | * Represents a {@link BlurTeam} designed for spectating players. 24 | */ 25 | public class SpectatorTeam extends BlurTeam { 26 | 27 | public static final String TEAM_ID = "spectators"; 28 | 29 | public SpectatorTeam(TeamManager manager) { 30 | super(manager, BlurTeam.builder() 31 | .id(TEAM_ID) 32 | .name("Spectators") 33 | .max(9001) 34 | .maxOverfill(9001) 35 | .chatColor(ChatColor.WHITE) 36 | .collisionRule(CollisionRule.NOONE) 37 | .nametagVisibility(NametagVisibility.NOONE) 38 | .color(Color.WHITE)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/StrategyPriority.java: -------------------------------------------------------------------------------- 1 | package com.blurengine.blur.modules.teams; 2 | 3 | public enum StrategyPriority { 4 | HIGHEST(0), 5 | HIGH(1), 6 | NORMAL(2), 7 | LOWEST(3), 8 | LOW(4); 9 | 10 | private final int slot; 11 | 12 | private StrategyPriority(int slot) { 13 | this.slot = slot; 14 | } 15 | 16 | public int getSlot() { 17 | return this.slot; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/TeamAssignmentStrategy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams 18 | 19 | import com.blurengine.blur.session.BlurPlayer 20 | import java.util.function.Supplier 21 | 22 | /** 23 | * Represents a strategical class that outputs a [BlurTeam] for a given [BlurPlayer]. 24 | * 25 | * [TeamAssignmentStrategy] are registered in [TeamManager] for gameplay feature. 26 | */ 27 | interface TeamAssignmentStrategy { 28 | val teams: Supplier> 29 | 30 | fun getTeam(blurPlayer: BlurPlayer): BlurTeam? 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/TeamsModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams; 18 | 19 | import com.blurengine.blur.framework.Module; 20 | import com.blurengine.blur.framework.ModuleData; 21 | import com.blurengine.blur.framework.ModuleInfo; 22 | import com.blurengine.blur.framework.ModuleManager; 23 | import com.blurengine.blur.framework.ModuleParseException; 24 | import com.blurengine.blur.framework.SerializedModule; 25 | import com.blurengine.blur.modules.filters.Filter; 26 | import com.blurengine.blur.modules.teams.TeamsModule.TeamsData; 27 | 28 | import java.util.List; 29 | 30 | import pluginbase.config.annotation.SerializeWith; 31 | 32 | /** 33 | * Represents a {@link Module} that allows for the creation of {@link Filter} and nothing else. Intended for user convenience. 34 | */ 35 | @ModuleInfo(name = "Teams", dataClass = TeamsData.class) 36 | public class TeamsModule extends Module { 37 | 38 | private TeamsModule(ModuleManager moduleManager) { 39 | super(moduleManager); 40 | } 41 | 42 | public static final class TeamsData implements ModuleData { 43 | 44 | @SerializeWith(TeamSerializer.class) 45 | private List teams; 46 | 47 | @Override 48 | public Module parse(ModuleManager moduleManager, SerializedModule serialized) throws ModuleParseException { 49 | serialized.load(this); 50 | return new TeamsModule(moduleManager); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/events/PlayerChangeTeamEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams.events; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.players.BlurPlayerEvent; 22 | import com.blurengine.blur.modules.teams.BlurTeam; 23 | import com.blurengine.blur.session.BlurPlayer; 24 | 25 | import org.bukkit.event.Cancellable; 26 | import org.bukkit.event.HandlerList; 27 | 28 | import java.util.Optional; 29 | 30 | import javax.annotation.Nonnull; 31 | 32 | /** 33 | * Represents a {@link BlurPlayerEvent} where a player's {@link BlurTeam} has changed. 34 | */ 35 | public class PlayerChangeTeamEvent extends BlurPlayerEvent implements Cancellable { 36 | 37 | private final BlurTeam oldTeam; 38 | private BlurTeam newTeam; 39 | 40 | public PlayerChangeTeamEvent(@Nonnull BlurPlayer blurPlayer, BlurTeam oldTeam, BlurTeam newTeam) { 41 | super(Preconditions.checkNotNull(blurPlayer, "blurPlayer cannot be null."), blurPlayer.getSession()); 42 | this.oldTeam = oldTeam; 43 | this.newTeam = newTeam; 44 | } 45 | 46 | public Optional getOldTeam() { 47 | return Optional.ofNullable(oldTeam); 48 | } 49 | 50 | public Optional getNewTeam() { 51 | return Optional.ofNullable(newTeam); 52 | } 53 | 54 | public void setNewTeam(BlurTeam newTeam) { 55 | this.newTeam = newTeam; 56 | } 57 | 58 | private boolean cancelled; 59 | 60 | @Override 61 | public boolean isCancelled() { return cancelled; } 62 | 63 | @Override 64 | public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } 65 | 66 | private static final HandlerList handlerList = new HandlerList(); 67 | 68 | @Override 69 | public HandlerList getHandlers() { return handlerList; } 70 | 71 | public static HandlerList getHandlerList() { return handlerList; } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/events/TeamEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams.events; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.events.session.BlurSessionEvent; 22 | import com.blurengine.blur.modules.teams.BlurTeam; 23 | 24 | /** 25 | * Represents a {@link BlurTeam} event. 26 | */ 27 | public abstract class TeamEvent extends BlurSessionEvent { 28 | 29 | protected final BlurTeam team; 30 | 31 | public TeamEvent(BlurTeam team) { 32 | super(Preconditions.checkNotNull(team, "team cannot be null.").getManager().getSession()); 33 | this.team = team; 34 | } 35 | 36 | public BlurTeam getTeam() { 37 | return team; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/teams/events/TeamRenameEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.teams.events; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import com.blurengine.blur.modules.teams.BlurTeam; 22 | 23 | import org.bukkit.event.HandlerList; 24 | 25 | import javax.annotation.Nonnull; 26 | import javax.annotation.Nullable; 27 | 28 | /** 29 | * Called when a {@link BlurTeam}'s name changes. 30 | */ 31 | public class TeamRenameEvent extends TeamEvent { 32 | 33 | private String oldName; 34 | private String newName; 35 | 36 | public TeamRenameEvent(@Nonnull BlurTeam team, @Nonnull String oldName, @Nullable String newName) { 37 | super(team); 38 | this.oldName = Preconditions.checkNotNull(oldName, "oldName cannot be null."); 39 | this.newName = Preconditions.checkNotNull(newName, "newName cannot be null."); 40 | } 41 | 42 | public String getOldName() { 43 | return oldName; 44 | } 45 | 46 | public String getNewName() { 47 | return newName; 48 | } 49 | 50 | private static final HandlerList handlerList = new HandlerList(); 51 | 52 | @Override 53 | public HandlerList getHandlers() { return handlerList; } 54 | 55 | public static HandlerList getHandlerList() { return handlerList; } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/modules/vanillafixes/RevertProjectileVelocity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.modules.vanillafixes 18 | 19 | import com.blurengine.blur.framework.Module 20 | import com.blurengine.blur.framework.ModuleInfo 21 | import com.blurengine.blur.framework.ModuleManager 22 | 23 | import org.bukkit.entity.Player 24 | import org.bukkit.event.EventHandler 25 | import org.bukkit.event.entity.ProjectileLaunchEvent 26 | 27 | /** 28 | * Fixes Minecraft 1.9 y projectile addition to projectile throwing. 29 | * @author Elijah "Xorgon" Andrews 30 | */ 31 | @ModuleInfo(name = "RevertProjectileVelocity") 32 | class RevertProjectileVelocity(moduleManager: ModuleManager) : Module(moduleManager) { 33 | 34 | @EventHandler 35 | fun onProjectileLaunch(event: ProjectileLaunchEvent) { 36 | val entity = event.entity 37 | if (entity.shooter is Player) { 38 | val player = entity.shooter as Player 39 | val speed = entity.velocity.length() 40 | entity.velocity = player.location.direction.multiply(speed) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/properties/BlurConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.properties; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | /** 23 | * Represents a class for deserializing a blur map configuration. 24 | */ 25 | public class BlurConfig { 26 | 27 | private List modules = Arrays.asList(""); 28 | 29 | public List getModules() { 30 | return modules; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/serializers/ComponentSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.serializers 18 | 19 | import com.blurengine.blur.text.TextParsers 20 | import net.md_5.bungee.api.chat.BaseComponent 21 | import pluginbase.config.serializers.Serializer 22 | import pluginbase.config.serializers.SerializerSet 23 | 24 | class ComponentSerializer: Serializer { 25 | override fun deserialize(serialized: Any?, wantedType: Class<*>, serializerSet: SerializerSet): BaseComponent? { 26 | if (serialized == null) return null 27 | if (serialized !is String) throw IllegalArgumentException("Expecting string, got ${serialized.javaClass.typeName}") 28 | return TextParsers.XML_PARSER.parse(serialized) 29 | } 30 | 31 | override fun serialize(`object`: BaseComponent?, serializerSet: SerializerSet): Any? { 32 | throw UnsupportedOperationException() 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/serializers/XmlComponentSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.serializers 18 | 19 | import com.blurengine.blur.text.TextParsers 20 | import net.md_5.bungee.api.chat.BaseComponent 21 | import pluginbase.config.serializers.Serializer 22 | import pluginbase.config.serializers.SerializerSet 23 | 24 | class XmlComponentSerializer : Serializer { 25 | override fun deserialize(serialized: Any?, wantedType: Class<*>, serializerSet: SerializerSet): BaseComponent? { 26 | if (serialized == null) return null 27 | if (serialized !is String) throw IllegalArgumentException("Expecting string, got ${serialized.javaClass.typeName}") 28 | return TextParsers.XML_PARSER.parse(serialized) 29 | } 30 | 31 | override fun serialize(`object`: BaseComponent?, serializerSet: SerializerSet): Any? { 32 | throw UnsupportedOperationException() 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/serializers/thirdparty/VersionSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.serializers.thirdparty 18 | 19 | import com.github.zafarkhaja.semver.Version 20 | import pluginbase.config.serializers.Serializer 21 | import pluginbase.config.serializers.SerializerSet 22 | 23 | class VersionSerializer : Serializer { 24 | override fun serialize(`object`: Version?, serializerSet: SerializerSet): Any? { 25 | return `object`.toString() 26 | } 27 | 28 | override fun deserialize(serialized: Any?, wantedType: Class<*>, serializerSet: SerializerSet): Version? { 29 | if (serialized == null) return null 30 | require(serialized is String || serialized is Number) { "version must be a string" } 31 | var serialized = serialized 32 | if (serialized is Number) { 33 | serialized = "${serialized.toDouble()}.0" 34 | } 35 | return Version.valueOf(serialized.toString()) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/session/SessionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.session; 18 | 19 | import com.google.common.base.Preconditions; 20 | import com.google.common.collect.Iterables; 21 | 22 | import com.blurengine.blur.Blur; 23 | 24 | import java.util.Collection; 25 | import java.util.Collections; 26 | import java.util.HashSet; 27 | import java.util.Set; 28 | 29 | import javax.annotation.Nonnull; 30 | 31 | /** 32 | * Represents a {@link BlurSession} manager. Only one SessionManager instance should exist at any one time. 33 | */ 34 | public class SessionManager { 35 | 36 | protected final Blur blur; 37 | private final Set blurSessions = new HashSet<>(); 38 | 39 | public SessionManager(Blur blur) { 40 | this.blur = blur; 41 | } 42 | 43 | public Blur getBlur() { 44 | return blur; 45 | } 46 | 47 | public boolean hasSession(@Nonnull BlurSession blurSession) { 48 | Preconditions.checkNotNull(blurSession, "blurSession cannot be null."); 49 | return this.blurSessions.contains(blurSession); 50 | } 51 | 52 | public boolean addSession(@Nonnull BlurSession blurSession) { 53 | Preconditions.checkNotNull(blurSession, "blurSession cannot be null."); 54 | return this.blurSessions.add(blurSession); 55 | } 56 | 57 | public boolean removeSession(@Nonnull BlurSession blurSession) { 58 | Preconditions.checkNotNull(blurSession, "blurSession cannot be null."); 59 | return this.blurSessions.remove(blurSession); 60 | } 61 | 62 | public Collection getBlurSessions() { 63 | return Collections.unmodifiableCollection(blurSessions); 64 | } 65 | 66 | public BlurSession getFirstSession() { 67 | return this.blurSessions.isEmpty() ? null : Iterables.get(this.blurSessions, 0); 68 | } 69 | 70 | public BlurSession getLastSession() { 71 | return this.blurSessions.isEmpty() ? null : Iterables.get(this.blurSessions, this.blurSessions.size() - 1); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/supervisor/SimpleAmendable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.supervisor; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import java.util.LinkedHashMap; 22 | import java.util.Map; 23 | 24 | import javax.annotation.Nonnull; 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * Created by Ali on 06/02/2016. 29 | */ 30 | public class SimpleAmendable implements Amendable { 31 | 32 | Map entries = new LinkedHashMap<>(); 33 | 34 | @Override 35 | public void append(@Nonnull String key, @Nullable Object value) { 36 | Preconditions.checkNotNull(key, "key cannot be null."); 37 | this.entries.put(key, value); 38 | } 39 | 40 | @Override 41 | public Map getEntries() { 42 | return this.entries; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/supervisor/SupervisorContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.supervisor; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | /** 22 | * Represents a compatible extension for linking with Supervisor. To use, simply implement this interface in your class, such as Module class, 23 | * and when appropriate Blur will invoke the {@link #run(Amendable)} when Supervisor requests information. 24 | *

25 | * The purpose of this class is a middle man between Blur and Supervisor to ensure compatibility and optionality to make Modules function with or 26 | * without Supervisor. 27 | */ 28 | public interface SupervisorContext { 29 | 30 | void run(@Nonnull Amendable amendable); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/text/TextParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.text 18 | 19 | import com.blurengine.blur.text.xml.XmlParser 20 | import net.md_5.bungee.api.chat.BaseComponent 21 | 22 | interface TextParser { 23 | 24 | /** 25 | * Parses a [String] using this Parser. 26 | * @param source source to parse 27 | * @return an instance of [BaseComponent] with the parsed `source` 28 | */ 29 | fun parse(source: String): BaseComponent 30 | } 31 | 32 | object TextParsers { 33 | @JvmField val XML_PARSER = XmlParser() 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/utils/CollectionsExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.utils 18 | 19 | fun > Iterable.allMin(): List = allMinBy { it } 20 | 21 | inline fun > Iterable.allMinBy(selector: (T) -> R): List { 22 | val iterator = iterator() 23 | if (!iterator.hasNext()) return listOf() 24 | val maxElems = mutableListOf(iterator.next()) 25 | var maxValue = selector(maxElems.first()) 26 | while (iterator.hasNext()) { 27 | val next = iterator.next() 28 | val value = selector(next) 29 | inner@for (maxElem in maxElems) { 30 | if (value <= maxValue) { 31 | if (value < maxValue) { // new max value 32 | maxElems.clear() 33 | maxValue = value 34 | } 35 | maxElems.add(next) 36 | break@inner 37 | } 38 | } 39 | } 40 | return maxElems 41 | } 42 | 43 | fun > Iterable.allMax(): List = allMaxBy { it } 44 | 45 | inline fun > Iterable.allMaxBy(selector: (T) -> R): List { 46 | val iterator = iterator() 47 | if (!iterator.hasNext()) return listOf() 48 | val maxElems = mutableListOf(iterator.next()) 49 | var maxValue = selector(maxElems.first()) 50 | while (iterator.hasNext()) { 51 | val next = iterator.next() 52 | val value = selector(next) 53 | inner@for (maxElem in maxElems) { 54 | if (value >= maxValue) { 55 | if (value > maxValue) { // new max value 56 | maxElems.clear() 57 | maxValue = value 58 | } 59 | maxElems.add(next) 60 | break@inner 61 | } 62 | } 63 | } 64 | return maxElems 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/blurengine/blur/utils/relationalops/Relational.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.utils.relationalops; 18 | 19 | import com.blurengine.blur.utils.relationalops.Relationals.RelationalStaticOp; 20 | 21 | import java.util.function.BiFunction; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | /** 26 | * Represents a relational interface between two relatable objects that can be compared by the implementation of {@link #apply(Object, Object)}. 27 | */ 28 | public interface Relational extends BiFunction { 29 | 30 | /** 31 | * Returns a new Relational that inverts the non-zero integer result this relational returns. Where result == 0, 0 is returned. Where result is 32 | * {@code >0}, {@code -n} is returned. Where result is {@code <0}, {@code +n} is returned. 33 | * 34 | * @return new relational 35 | */ 36 | default Relational inversed() { 37 | return Relationals.inversed(this); 38 | } 39 | 40 | default Relational staticOp(@Nonnull RelationalOperator operator) { 41 | return Relationals.staticOp(this, operator); 42 | } 43 | 44 | default boolean isStaticOp() { 45 | return this instanceof RelationalStaticOp; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ${plugin.name} 2 | main: ${main.class} 3 | version: ${project.version}-git-${git.commit.id.abbrev} 4 | load: STARTUP 5 | authors: [SupaHam] 6 | api-version: 1.13 7 | -------------------------------------------------------------------------------- /src/test/java/FilterLexerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import com.blurengine.blur.modules.filters.Filter; 20 | import com.blurengine.blur.modules.filters.Filter.FilterResponse; 21 | import com.blurengine.blur.modules.filters.lexer.FilterRecursiveDescentParser; 22 | 23 | import org.junit.Test; 24 | 25 | /** 26 | * Tests the filter lexer. 27 | */ 28 | public class FilterLexerTest { 29 | 30 | public static final String TRUE = "true"; 31 | public static final String TRUE_OR_FALSE = "true|false"; 32 | public static final String TRUE_OR_FALSE_WHITESPACE = "true | false"; 33 | public static final String COMPLEX_EXPRESSION_RETURN_FALSE = "((false & true) & true) & (true & false) | ((false) | false)"; 34 | 35 | @Test 36 | public void testTrue() throws Exception { 37 | Filter filter = parse(TRUE); 38 | assertTrue(filter.test(null) == FilterResponse.ALLOW); 39 | } 40 | 41 | @Test 42 | public void testTrueOrFalse() throws Exception { 43 | Filter filter = parse(TRUE_OR_FALSE); 44 | assertTrue(filter.test(null) == FilterResponse.ALLOW); 45 | 46 | filter = parse(TRUE_OR_FALSE_WHITESPACE); 47 | assertTrue(filter.test(null) == FilterResponse.ALLOW); 48 | } 49 | 50 | @Test 51 | public void testComplex() throws Exception { 52 | Filter filter = parse(COMPLEX_EXPRESSION_RETURN_FALSE); 53 | assertTrue(filter.test(null) == FilterResponse.DENY); 54 | } 55 | 56 | public Filter parse(String str) { 57 | return new FilterRecursiveDescentParser(a -> null, str).call(); // FIXME First param is a null supplier for filter references by id. 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/blurengine/blur/CollectionsExtensionsTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur 18 | 19 | import com.blurengine.blur.utils.allMaxBy 20 | import org.junit.Assert 21 | import org.junit.Test 22 | 23 | class CollectionsExtensionsTest { 24 | @Test 25 | fun testAllMaxBy() { 26 | val values = listOf(1, 2, 2, 3, 4, 4 ) 27 | Assert.assertEquals(values.allMaxBy { it }, listOf(4, 4)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/blurengine/blur/utils/CollectionsTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Ali Moghnieh 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.blurengine.blur.utils 18 | 19 | import org.junit.Assert 20 | import org.junit.Test 21 | 22 | class CollectionsTests { 23 | @Test 24 | fun AllMinSingle() { 25 | val collection = listOf(1, 4, 2, 4, 3, 2) 26 | val minCollection = collection.allMin() 27 | Assert.assertEquals(minCollection, listOf(1)) 28 | } 29 | 30 | @Test 31 | fun AllMaxSingle() { 32 | val collection = listOf(1, 4, 2, 3, 1, 2) 33 | val minCollection = collection.allMax() 34 | Assert.assertEquals(minCollection, listOf(4)) 35 | } 36 | 37 | @Test 38 | fun AllMinMultiple() { 39 | val collection = listOf(1, 4, 2, 4, 3, 1, 2) 40 | val minCollection = collection.allMin() 41 | Assert.assertEquals(minCollection, listOf(1, 1)) 42 | } 43 | 44 | @Test 45 | fun AllMaxMultiple() { 46 | val collection = listOf(1, 4, 2, 4, 3, 1, 2) 47 | val minCollection = collection.allMax() 48 | Assert.assertEquals(minCollection, listOf(4, 4)) 49 | } 50 | } 51 | --------------------------------------------------------------------------------