Skip to content

Commit

Permalink
Integration Update
Browse files Browse the repository at this point in the history
- Integration with DutchyTPA and DutchyHome
- If DutchyTPA is installed, it will listen to its dedicated event, instead of /tpa
- if DutchyHome is installed, it will listen to its dedicated event, instead of /home

REQUIRES DutchyTPA 1.1.0 and DutchyHome 1.1.0 TO WORK!
  • Loading branch information
TheDutchMC committed Jul 1, 2020
1 parent efc5617 commit 14b1b14
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ plugins {
id 'java'
}

version = '1.16_1.0.0'
version = '1.16_1.0.1'

repositories {
jcenter()
mavenCentral();
mavenLocal();

maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
Expand All @@ -19,4 +20,7 @@ repositories {

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'

compileOnly 'nl.thedutchmc:dutchyhome:1.1.0'
compileOnly 'nl.thedutchmc:dutchytpa:1.1.0'
}
13 changes: 12 additions & 1 deletion src/main/java/nl/thedutchmc/dutchyback/Back.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,30 @@

import nl.thedutchmc.dutchyback.listeners.PlayerCommandPreprocessEventListener;
import nl.thedutchmc.dutchyback.listeners.PlayerDeathEventListener;
import nl.thedutchmc.dutchyback.listeners.SuccesfulHomeTeleportEventListener;
import nl.thedutchmc.dutchyback.listeners.SuccessfulTpaEventListener;

public class Back extends JavaPlugin {

public static HashMap<UUID, Location> playerBackLocs = new HashMap<>();

public static boolean isDutchyTpaInstalled = false;
public static boolean isDutchyHomeInstalled = false;

@Override
public void onEnable() {

if(Bukkit.getPluginManager().isPluginEnabled("DutchyTPA")) isDutchyTpaInstalled = true;
if(Bukkit.getPluginManager().isPluginEnabled("DutchyHome")) isDutchyHomeInstalled = true;

Bukkit.getPluginManager().registerEvents(new PlayerCommandPreprocessEventListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerDeathEventListener(), this);

if(isDutchyTpaInstalled) Bukkit.getPluginManager().registerEvents(new SuccessfulTpaEventListener(), this);
if(isDutchyHomeInstalled) Bukkit.getPluginManager().registerEvents(new SuccesfulHomeTeleportEventListener(), this);


getCommand("back").setExecutor(new CommandHandler());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) {

String command = event.getMessage().split(" ")[0];

if(command.equals("/tp") || command.equals("/tpa") || command.equals("/home")) {
if(command.equals("/tp") || (command.equals("/tpa") && !Back.isDutchyTpaInstalled) || (command.equals("/home") && !Back.isDutchyHomeInstalled)) {

Location loc = event.getPlayer().getLocation();
UUID uuid = event.getPlayer().getUniqueId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nl.thedutchmc.dutchyback.listeners;

import java.util.UUID;

import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import nl.thedutchmc.dutchyback.Back;
import nl.thedutchmc.dutchyhome.SuccessfulHomeTeleportEvent;

public class SuccesfulHomeTeleportEventListener implements Listener {

@EventHandler
public void onSuccesfulTpaEvent(SuccessfulHomeTeleportEvent event) {


Location loc = event.getLocationBeforeHomeTp();
UUID uuid = event.getPlayer().getUniqueId();

if(Back.playerBackLocs.containsKey(uuid)) {
Back.playerBackLocs.replace(uuid, loc);
} else {
Back.playerBackLocs.put(uuid, loc);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nl.thedutchmc.dutchyback.listeners;

import java.util.UUID;

import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import nl.thedutchmc.dutchyback.Back;
import nl.thedutchmc.dutchytpa.SuccessfulTpaEvent;

public class SuccessfulTpaEventListener implements Listener {

@EventHandler
public void onSuccessfulTpaEvent(SuccessfulTpaEvent event) {

Location loc = event.getLocationBeforeTpa();
UUID uuid = event.getPlayer().getUniqueId();

if(Back.playerBackLocs.containsKey(uuid)) {
Back.playerBackLocs.replace(uuid, loc);
} else {
Back.playerBackLocs.put(uuid, loc);
}
}

}
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: DutchyBack
main: nl.thedutchmc.dutchyback.Back
version: 1.0.0
version: 1.0.1
api-version: 1.16
author: TheDutchMC
description: A plugin which adds /back
softdepend: [DutchyTPA, DutchyHome]
commands:
back:
description: Go to your previous location

0 comments on commit 14b1b14

Please sign in to comment.