Skip to content

Commit

Permalink
Added jitpack.yml file, some language+color issues fixed, added liste…
Browse files Browse the repository at this point in the history
…ner for PlayerTransferEvent, fired by OfflinePlayers, version bump to 2.1.0
  • Loading branch information
TheDutchMC committed Feb 9, 2021
1 parent 2c6154c commit c5e64ac
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'eclipse'
}

version = '2.0.0'
version = '2.1.0'

sourceCompatibility = 1.11
targetCompatibility = 1.11
Expand All @@ -20,15 +20,20 @@ repositories {
jcenter()
maven{ url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" }
maven{ url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://jitpack.io' }
maven { url 'https://jitpack.io' }
mavenLocal()
}

dependencies {
//Dev only:
//compileOnly 'nl.thedutchmc:dutchycore:0.0.15'
//compileOnly 'nl.thedutchmc:dutchycore:0.0.33'
//compileOnly 'nl.thedutchmc:offlineplayers:1.1.0'

//bug in jitpack, cant use nl.thedutchmc here :/
compileOnly 'com.github.DutchyPlugins:Dutchycore:0.0.15-R3'
compileOnly 'com.github.DutchyPlugins:DutchyCore:0.0.34'
compileOnly 'com.github.DutchyPlugins:OfflinePlayers:1.1.0'

//Spigot API
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
}

Expand Down
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
21 changes: 20 additions & 1 deletion src/main/java/nl/thedutchmc/dutchyhome/DutchyHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
import org.bukkit.permissions.PermissionDefault;
import nl.thedutchmc.dutchycore.DutchyCore;
import nl.thedutchmc.dutchycore.module.PluginModule;
import nl.thedutchmc.dutchycore.module.annotations.Nullable;
import nl.thedutchmc.dutchycore.annotations.Nullable;
import nl.thedutchmc.dutchycore.module.file.ModuleFileHandler;
import nl.thedutchmc.dutchycore.module.file.ModuleStorage;
import nl.thedutchmc.dutchyhome.commands.DelHomeCommandExecutor;
import nl.thedutchmc.dutchyhome.commands.HomeCommandExecutor;
import nl.thedutchmc.dutchyhome.commands.HomesCommandExecutor;
import nl.thedutchmc.dutchyhome.commands.SetHomeCommandExecutor;
import nl.thedutchmc.dutchyhome.listeners.PlayerTransferEventListener;
import nl.thedutchmc.dutchyhome.tabcompleters.DelHomeCommandCompleter;
import nl.thedutchmc.dutchyhome.tabcompleters.HomeCommandCompleter;
import nl.thedutchmc.dutchyhome.tabcompleters.HomesCommandCompleter;
import nl.thedutchmc.dutchyhome.tabcompleters.SetHomeCommandCompleter;
import nl.thedutchmc.offlineplayers.events.PlayerTransferEvent;

public class DutchyHome extends PluginModule {

Expand Down Expand Up @@ -130,6 +132,15 @@ public void enable(DutchyCore core) {
super.logInfo("Initialization complete!");
}

@Override
public void postEnable() {
//Register event listeners
if(super.isModuleRegistered("OfflinePlayers")) {
super.logInfo("OfflinePlayers is installed. Enabling listener!");
super.registerModuleEventListener(new PlayerTransferEventListener(this), PlayerTransferEvent.class);
}
}

/**
* Write a home to disk
* @param homeName The name of the home
Expand Down Expand Up @@ -199,4 +210,12 @@ public PlayerHomes getPlayerHomes(UUID uuid) {
public void setPlayerHome(UUID uuid, PlayerHomes playerHomes) {
this.playerHomes.put(uuid, playerHomes);
}

/**
* Remove a PlayerHomes for a player
* @param uuid The UUID of the player
*/
public void delPlayerHome(UUID uuid) {
this.playerHomes.remove(uuid);
}
}
2 changes: 1 addition & 1 deletion src/main/java/nl/thedutchmc/dutchyhome/PlayerHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.bukkit.Location;

import nl.thedutchmc.dutchycore.module.annotations.Nullable;
import nl.thedutchmc.dutchycore.annotations.Nullable;

public class PlayerHomes {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean fire(CommandSender sender, String[] args) {

//Verify that the amount is an integer
if(!Utils.verifyPositiveInteger(parts[parts.length -1])) {
sender.sendMessage("Please contact your server administrator. They have made a mistake with permissions for DutchyHome!");
sender.sendMessage(ChatColor.RED + "Please contact your server administrator. They have made a mistake with permissions for DutchyHome!");
return true;
}

Expand All @@ -98,7 +98,7 @@ public boolean fire(CommandSender sender, String[] args) {
//Check if the player has reached the home limit
int amountOfHomes = playerHomes.getAllHomes().size();
if(amountOfHomes >= maxHomes) {
sender.sendMessage("You have reached the limit of homes you can set! Remove a home before setting a new one.");
sender.sendMessage(ChatColor.RED + "You have reached the limit of homes you can set! Remove a home before setting a new one.");
return true;
}

Expand All @@ -120,7 +120,7 @@ public boolean fire(CommandSender sender, String[] args) {

//Send the message to the player
String message = "Set home %s at %d, %d, %d!";
message = Utils.processColours(message,
message = Utils.processColours(ChatColor.GOLD + message,
new Triple<String, ChatColor, ChatColor>("%s", ChatColor.RED, ChatColor.GOLD),
new Triple<String, ChatColor, ChatColor>("%d", ChatColor.RED, ChatColor.GOLD));
sender.sendMessage(String.format(message, homeName, playerCurrentLoc.getBlockX(), playerCurrentLoc.getBlockY(), playerCurrentLoc.getBlockZ()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nl.thedutchmc.dutchyhome.listeners;

import java.util.Map;

import org.bukkit.Location;

import nl.thedutchmc.dutchycore.module.events.ModuleEvent;
import nl.thedutchmc.dutchycore.module.events.ModuleEventListener;
import nl.thedutchmc.dutchyhome.DutchyHome;
import nl.thedutchmc.dutchyhome.PlayerHomes;
import nl.thedutchmc.offlineplayers.events.PlayerTransferEvent;

public class PlayerTransferEventListener implements ModuleEventListener {

private DutchyHome module;

public PlayerTransferEventListener(DutchyHome module) {
this.module = module;
}

@Override
public void onEvent(ModuleEvent event) {
PlayerTransferEvent pte = (PlayerTransferEvent) event;

PlayerHomes playerHomesOld = this.module.getPlayerHomes(pte.getOldUUID());

//Create a new PlayerHoems object
PlayerHomes playerHomesNew = new PlayerHomes(pte.getNewUUID());

//Add all h omes from the playerHomesOld to the playerHomesNew
for(Map.Entry<String, Location> entry : playerHomesOld.getAllHomes().entrySet()) {
playerHomesNew.setHome(entry.getKey(), entry.getValue());
}

//Set the new PlayerHomes, and remove the old
this.module.setPlayerHome(pte.getNewUUID(), playerHomesNew);
this.module.delPlayerHome(pte.getOldUUID());

//Write memory to disk
this.module.writeMemory();
}
}

0 comments on commit c5e64ac

Please sign in to comment.