Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 23 additions & 54 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,33 @@
<modelVersion>4.0.0</modelVersion>

<groupId>net.playeranalytics</groupId>
<artifactId>Extension-template</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>Extension-CMI</artifactId>
<version>9.7.4.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>

<!-- Platforms -->

<!-- <repository>-->
<!-- <id>spigot-repo</id>-->
<!-- <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>sponge-repo</id>-->
<!-- <url>https://repo.spongepowered.org/repository/maven-public/</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>bungeecord-repo</id>-->
<!-- <url>https://oss.sonatype.org/content/repositories/snapshots</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>velocity-repo</id>-->
<!-- <url>https://repo.velocitypowered.com/snapshots/</url>-->
<!-- </repository>-->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>

<repository>
<id>plan-repo</id>
Expand All @@ -67,39 +54,21 @@
</dependency>

<!-- Plugin API Dependency -->
<!-- <dependency>-->
<!-- <groupId></groupId>-->
<!-- <artifactId></artifactId>-->
<!-- <version></version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>CMI-API</groupId>
<artifactId>CMI-API</artifactId>
<version>9.7.4.1</version>
<scope>provided</scope>
</dependency>

<!-- Platforms -->

<!-- <dependency>-->
<!-- <groupId>org.spigotmc</groupId>-->
<!-- <artifactId>spigot-api</artifactId>-->
<!-- <version>1.16.5-R0.1-SNAPSHOT</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.spongepowered</groupId>-->
<!-- <artifactId>spongeapi</artifactId>-->
<!-- <version>7.3.0</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>net.md-5</groupId>-->
<!-- <artifactId>bungeecord-api</artifactId>-->
<!-- <version>1.16-R0.4</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.velocitypowered</groupId>-->
<!-- <artifactId>velocity-api</artifactId>-->
<!-- <version>1.0.0-SNAPSHOT</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
Expand Down
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) {
Copy link
Contributor

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

Player player = event.getUser().getPlayer();

caller.updatePlayerData(player.getUniqueId(), player.getName());
}

}
152 changes: 152 additions & 0 deletions src/main/java/net/playeranalytics/extension/cmi/CMIExtension.java
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();
}
}
Loading