Skip to content

Commit

Permalink
0.1.27
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaytak committed Oct 11, 2024
1 parent 43ecc52 commit ff33f5d
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 4 deletions.
Binary file modified .gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/modules/PlayerPromote.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.jaytak'
version = '0.1.22'
version = '0.1.27'

repositories {
mavenCentral()
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion build/resources/main/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PlayerPromote
version: '0.1.22'
version: '0.1.27'
main: com.jaytak.playerPromote.PlayerPromote
api-version: '1.21'
commands:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
34 changes: 33 additions & 1 deletion src/main/java/com/jaytak/playerPromote/PlayerPromote.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public final class PlayerPromote extends JavaPlugin implements Listener {
Expand All @@ -23,12 +28,24 @@ public final class PlayerPromote extends JavaPlugin implements Listener {
private String alreadyPromotedMessage = "";
private String initalGroup = "default";
private String promoteToGroup = "group.player";
private File historyFile;


@Override
public void onEnable() {
// Plugin startup logic
getServer().getPluginManager().registerEvents(this, this);
saveDefaultConfig();
historyFile = new File(getDataFolder(), "PlayerAcceptHistory.txt");
if (!historyFile.exists()) {
try{
getDataFolder().mkdirs();
historyFile.createNewFile();
} catch (IOException e) {
getLogger().severe("Failed to create history file.");
throw new RuntimeException(e);
}
}
loadConfig();
this.getCommand("agree").setExecutor(new AgreeCommand());

Expand All @@ -54,6 +71,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
getLogger().info("Player Joined! " + event.getPlayer().getName());
if (!event.getPlayer().hasPlayedBefore() && newPlayerMessage != null && !newPlayerMessage.equals("DISABLED")) {
event.getPlayer().sendMessage(playerTitle + newPlayerMessage);
JTLogger("Player " + event.getPlayer().getName() + " joined for the first time and was sent the first join message.");
}
}

Expand All @@ -66,6 +84,16 @@ private void loadConfig(){
promoteToGroup = getConfig().getString("PromoteToGroup", "group.player");
}

private void JTLogger(String log){
try(FileWriter writer = new FileWriter(historyFile, true)){
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd:hh:mm:ss"));
writer.write("[" + timestamp + "] " + log + "\n");
}
catch (Exception e){
getLogger().severe("PlayerPromote. Failed to log to file. Exception:\n" + e);
}
}


public class AgreeCommand implements CommandExecutor {
@Override
Expand All @@ -78,8 +106,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player player = (Player) sender;

if (command.getName().equalsIgnoreCase("agree")) {
if (!player.hasPermission("agreeplugin.use")) {
if (!player.hasPermission("playerpromote.use")) {
player.sendMessage(playerTitle + "You do not have permission to use this command.");
JTLogger("Player " + player.getName() + " tried to use /agree but did not have permission.");
return true;
}

Expand All @@ -92,11 +121,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (user.getPrimaryGroup().equals(initalGroup)) {
user.data().add(Node.builder(promoteToGroup).build());
user.data().remove(Node.builder("group." + initalGroup).build());
luckPerms.getUserManager().saveUser(user);
JTLogger("Player " + player.getName() + " agreed to the rules, and was promoted from " + initalGroup + " to " + promoteToGroup);
player.sendMessage(playerTitle + promoteMessage);
}
else {
player.sendMessage(playerTitle + alreadyPromotedMessage);
JTLogger("Player " + player.getName() + " tried to use /agree but was already in a higher group.");
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PlayerPromote
version: '0.1.22'
version: '0.1.27'
main: com.jaytak.playerPromote.PlayerPromote
api-version: '1.21'
commands:
Expand Down

0 comments on commit ff33f5d

Please sign in to comment.