-
Notifications
You must be signed in to change notification settings - Fork 2
Version 1.0 CMI Extention #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
048dc66
Version 1.0 of the CMI extension with a feature copy of https://githu…
503865c
Corrected Author
2758a63
Changed package name to lowercase
7923936
Reworked to include economy in only one extension as requested
af3cba6
Reworked event registration as requested
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/net/playeranalytics/extension/cmi/CMIEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package net.playeranalytics.extension.cmi; | ||
|
|
||
|
|
||
| import com.Zrips.CMI.Containers.CMIUser; | ||
| import com.Zrips.CMI.events.*; | ||
| import com.djrapitops.plan.extension.Caller; | ||
| import com.djrapitops.plan.settings.ListenerService; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class CMIEventListener implements Listener { | ||
|
|
||
| private final Caller caller; | ||
|
|
||
| public CMIEventListener(Caller caller) { | ||
| this.caller = caller; | ||
| } | ||
|
|
||
| public void register() { | ||
| ListenerService.getInstance().registerListenerForPlan(this); | ||
| } | ||
|
|
||
| /* | ||
| Jail events | ||
| */ | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onJailEntered(CMIPlayerJailEvent event) { | ||
| CMIUser user = event.getUser(); | ||
| UUID playerUUID = user.getUniqueId(); | ||
| String playerName = user.getName(); | ||
|
|
||
| caller.updatePlayerData(playerUUID, playerName); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onJailLeft(CMIPlayerUnjailEvent event) { | ||
| CMIUser user = event.getUser(); | ||
| UUID playerUUID = user.getUniqueId(); | ||
| String playerName = user.getName(); | ||
|
|
||
| caller.updatePlayerData(playerUUID, playerName); | ||
| } | ||
|
|
||
| /* | ||
| Home events | ||
| */ | ||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onJailLeft(CMIUserHomeCreateEvent event) { | ||
| CMIUser user = event.getUser(); | ||
| UUID playerUUID = user.getUniqueId(); | ||
| String playerName = user.getName(); | ||
|
|
||
| caller.updatePlayerData(playerUUID, playerName); | ||
| } | ||
|
|
||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onJailLeft(CMIUserHomeRemoveEvent event) { | ||
| CMIUser user = event.getUser(); | ||
| UUID playerUUID = user.getUniqueId(); | ||
| String playerName = user.getName(); | ||
|
|
||
| caller.updatePlayerData(playerUUID, playerName); | ||
| } | ||
|
|
||
| /* | ||
| TODO: Implement mute Listener, currently unavailable through CMI API check https://github.com/Zrips/CMI-API/issues/37 | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onMuteStatusChange(MuteStatusChangeEvent event) { | ||
| IUser affected = event.getAffected(); | ||
| UUID playerUUID = affected.getBase().getUniqueId(); | ||
| String playerName = affected.getName(); | ||
|
|
||
| caller.updatePlayerData(playerUUID, playerName); | ||
| } | ||
|
|
||
| */ | ||
|
|
||
| /* | ||
| Money events | ||
| */ | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR) | ||
| public void onBalanceChange(CMIUserBalanceChangeEvent event) { | ||
| Player player = event.getUser().getPlayer(); | ||
|
|
||
| caller.updatePlayerData(player.getUniqueId(), player.getName()); | ||
| } | ||
|
|
||
| } | ||
152 changes: 152 additions & 0 deletions
152
src/main/java/net/playeranalytics/extension/cmi/CMIExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /* | ||
| Copyright(c) 2021 AuroraLS3 | ||
|
|
||
| The MIT License(MIT) | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files(the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions : | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| */ | ||
| package net.playeranalytics.extension.cmi; | ||
|
|
||
| import com.Zrips.CMI.CMI; | ||
| import com.Zrips.CMI.Containers.CMIUser; | ||
| import com.djrapitops.plan.extension.CallEvents; | ||
| import com.djrapitops.plan.extension.DataExtension; | ||
| import com.djrapitops.plan.extension.FormatType; | ||
| import com.djrapitops.plan.extension.NotReadyException; | ||
| import com.djrapitops.plan.extension.annotation.*; | ||
| import com.djrapitops.plan.extension.icon.Color; | ||
| import com.djrapitops.plan.extension.icon.Family; | ||
| import org.bukkit.plugin.java.JavaPlugin; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * DataExtension. | ||
| * | ||
| * @author YannicHock | ||
| */ | ||
| @PluginInfo(name = "CMI", iconName = "gear", iconFamily = Family.SOLID, color = Color.DEEP_ORANGE) | ||
| @TabInfo(tab = "Money", iconName = "coins", elementOrder = {}) | ||
| @TabInfo(tab = "General Info", iconName = "list", elementOrder = {}) | ||
| public class CMIExtension implements DataExtension { | ||
|
|
||
| private CMI cmi; | ||
|
|
||
| CMIExtension(boolean b) { | ||
| /* For test construction */ | ||
| } | ||
|
|
||
| CMIExtension() { | ||
| cmi = JavaPlugin.getPlugin(CMI.class); | ||
| } | ||
|
|
||
| @Override | ||
| public CallEvents[] callExtensionMethodsOn() { | ||
| return new CallEvents[]{ | ||
| CallEvents.PLAYER_JOIN, CallEvents.PLAYER_LEAVE, | ||
| CallEvents.SERVER_EXTENSION_REGISTER, CallEvents.SERVER_PERIODICAL | ||
| }; | ||
| } | ||
|
|
||
| private CMIUser getUser(UUID playerUUID) { | ||
| CMIUser user = cmi.getPlayerManager().getUser(playerUUID); | ||
| if (user == null) throw new NotReadyException(); | ||
| return user; | ||
| } | ||
|
|
||
| /* | ||
| General Info | ||
| */ | ||
|
|
||
| @BooleanProvider( | ||
| text = "Jailed", iconName = "ban", priority = 100, iconColor = Color.DEEP_ORANGE, conditionName = "isJailed" | ||
| ) | ||
| @Tab("General Info") | ||
| public boolean isJailed(UUID playerUUID) { | ||
| return getUser(playerUUID).isJailed(); | ||
| } | ||
|
|
||
| @Conditional("isJailed") | ||
| @NumberProvider( | ||
| text = "Jail Expires", iconName = "calendar-times", priority = 99, iconFamily = Family.REGULAR, iconColor = Color.DEEP_ORANGE, format = FormatType.DATE_SECOND | ||
| ) | ||
| @Tab("General Info") | ||
| public long jailTimeout(UUID playerUUID) { | ||
| return getUser(playerUUID).getJailedForTime(); | ||
| } | ||
|
|
||
| @BooleanProvider( | ||
| text = "Muted", iconName = "bell-slash", priority = 80, iconColor = Color.BLUE_GREY, conditionName = "isMuted" | ||
| ) | ||
| @Tab("General Info") | ||
| public boolean isMuted(UUID playerUUID) { | ||
| return getUser(playerUUID).isMuted(); | ||
| } | ||
|
|
||
| @Conditional("isMuted") | ||
| @NumberProvider( | ||
| text = "Mute Expires", iconName = "calendar-times", priority = 79, iconFamily = Family.REGULAR, iconColor = Color.BLUE_GREY, format = FormatType.DATE_SECOND | ||
| ) | ||
| @Tab("General Info") | ||
| public long muteTimeout(UUID playerUUID) { | ||
| return getUser(playerUUID).getMutedUntil(); | ||
| } | ||
|
|
||
| @StringProvider( | ||
| text = "homes", iconName = "home", priority = 70, iconColor = Color.GREEN | ||
| ) | ||
| @Tab("General Info") | ||
| public String playerHomes(UUID playerUUID) { | ||
| List<String> homes = getUser(playerUUID).getHomesList(); | ||
| if (homes.isEmpty()) { | ||
| return "-"; | ||
| } | ||
|
|
||
| Collections.sort(homes); | ||
|
|
||
| StringBuilder homeString = new StringBuilder(); | ||
| int size = homes.size(); | ||
|
|
||
| for (int i = 0; i < size; i++) { | ||
| homeString.append(homes.get(i)); | ||
| if (i < size - 1) { | ||
| homeString.append(", "); | ||
| } | ||
| } | ||
|
|
||
| return homeString.toString(); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| Money | ||
| */ | ||
| @DoubleProvider( | ||
| text = "Balance", iconName = "coins", priority = 60, iconColor = Color.GREEN | ||
| ) | ||
| @Tab("Money") | ||
| public double balance(UUID playerUUID) { | ||
| if (!cmi.getEconomyManager().isEnabled()) { | ||
| throw new NotReadyException(); | ||
| } | ||
|
|
||
| return getUser(playerUUID).getBalance(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event has the potential to be fired 100s of times per second when combined with something like Jobs that pays out per block mined. Considering that I will add a time based limiter on this updating the Plan data, since currently each call to updatePlayerData would fire ~24 transactions in Plan