Skip to content

Commit

Permalink
Updated for Paper 1.18.1.
Browse files Browse the repository at this point in the history
Not using adventure for now.
  • Loading branch information
krusic22 committed Dec 14, 2021
1 parent 1b8c9a5 commit 8679b3e
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 177 deletions.
26 changes: 13 additions & 13 deletions WelcomeWarps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.wasteofplastic</groupId>
<artifactId>WelcomeWarpSigns</artifactId>
<version>1.5</version>
<version>1.6</version>
<packaging>jar</packaging>

<name>com.wasteofplastic</name>
Expand Down Expand Up @@ -42,24 +42,24 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
</project>
29 changes: 14 additions & 15 deletions WelcomeWarps/src/com/wasteofplastic/wwarps/Messages.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.wasteofplastic.wwarps;

import java.util.*;

import com.wasteofplastic.wwarps.util.Util;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import com.wasteofplastic.wwarps.util.Util;
import java.util.*;

/**
* Handles offline messaging to players and teams
Expand Down Expand Up @@ -68,19 +67,19 @@ public void saveMessages() {
public boolean loadMessages() {
plugin.getLogger().info("Loading offline messages...");
try {
messageStore = Util.loadYamlFile("messages.yml");
if (messageStore.getConfigurationSection("messages") == null) {
messageStore.createSection("messages"); // This is only used to
// create
}
HashMap<String, Object> temp = (HashMap<String, Object>) messageStore.getConfigurationSection("messages").getValues(true);
for (String s : temp.keySet()) {
List<String> messageList = messageStore.getStringList("messages." + s);
if (!messageList.isEmpty()) {
messages.put(UUID.fromString(s), messageList);
messageStore = Util.loadYamlFile("messages.yml");
if (messageStore.getConfigurationSection("messages") == null) {
messageStore.createSection("messages"); // This is only used to
// create
}
}
return true;
HashMap<String, Object> temp = (HashMap<String, Object>) Objects.requireNonNull(messageStore.getConfigurationSection("messages")).getValues(true);
for (String s : temp.keySet()) {
List<String> messageList = messageStore.getStringList("messages." + s);
if (!messageList.isEmpty()) {
messages.put(UUID.fromString(s), messageList);
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
Expand Down
54 changes: 27 additions & 27 deletions WelcomeWarps/src/com/wasteofplastic/wwarps/WWarps.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package com.wasteofplastic.wwarps;

import java.util.HashMap;

import com.wasteofplastic.wwarps.commands.AdminCmd;
import com.wasteofplastic.wwarps.commands.WarpCmd;
import com.wasteofplastic.wwarps.listeners.JoinLeaveEvents;
import com.wasteofplastic.wwarps.panels.WarpPanel;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
Expand All @@ -29,10 +31,8 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import com.wasteofplastic.wwarps.commands.AdminCmd;
import com.wasteofplastic.wwarps.commands.WarpCmd;
import com.wasteofplastic.wwarps.listeners.JoinLeaveEvents;
import com.wasteofplastic.wwarps.panels.WarpPanel;
import java.util.HashMap;
import java.util.Objects;

/**
* @author tastybento
Expand Down Expand Up @@ -185,28 +185,28 @@ public void onDisable() {
*/
@Override
public void onEnable() {
plugin = this;
saveDefaultConfig();
// Load all the configuration of the plugin and localization strings
loadPluginConfig();
// Set up commands for this plugin
plugin = this;
saveDefaultConfig();
// Load all the configuration of the plugin and localization strings
loadPluginConfig();
// Set up commands for this plugin
WarpCmd warpCmd = new WarpCmd(this);
AdminCmd adminCmd = new AdminCmd(this);

getCommand("wwarp").setExecutor(warpCmd);
getCommand("wwarp").setTabCompleter(warpCmd);
getCommand("wwadmin").setExecutor(adminCmd);
// Register events
registerEvents();
// Have to do this a tick later to wait for all the worlds to load
getServer().getScheduler().runTask(this, () -> {
// Load warps
getWarpSignsListener().loadWarpList();
// Load the warp panel
warpPanel = new WarpPanel(plugin);
getServer().getPluginManager().registerEvents(warpPanel, plugin);
});
}
AdminCmd adminCmd = new AdminCmd(this);

Objects.requireNonNull(getCommand("wwarp")).setExecutor(warpCmd);
Objects.requireNonNull(getCommand("wwarp")).setTabCompleter(warpCmd);
Objects.requireNonNull(getCommand("wwadmin")).setExecutor(adminCmd);
// Register events
registerEvents();
// Have to do this a tick later to wait for all the worlds to load
getServer().getScheduler().runTask(this, () -> {
// Load warps
getWarpSignsListener().loadWarpList();
// Load the warp panel
warpPanel = new WarpPanel(plugin);
getServer().getPluginManager().registerEvents(warpPanel, plugin);
});
}

/**
* Registers events
Expand Down
91 changes: 43 additions & 48 deletions WelcomeWarps/src/com/wasteofplastic/wwarps/WarpSigns.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
*******************************************************************************/
package com.wasteofplastic.wwarps;

import java.util.*;
import java.util.Map.Entry;

import com.wasteofplastic.wwarps.util.Util;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
Expand All @@ -33,7 +30,8 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent;

import com.wasteofplastic.wwarps.util.Util;
import java.util.*;
import java.util.Map.Entry;

/**
* Handles warping in ASkyBlock Players can add one sign
Expand All @@ -56,21 +54,22 @@ public WarpSigns(WWarps plugin) {
this.warpList = new HashMap<>();
}

/**
* Checks to see if a sign has been broken
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onSignBreak(BlockBreakEvent e) {
Block b = e.getBlock();
Player player = e.getPlayer();
if (Settings.worldName.isEmpty() || Settings.worldName.contains(b.getWorld().getName())) {
if (Tag.SIGNS.isTagged(b.getType())) {
Sign s = (Sign) b.getState();
//plugin.getLogger().info("DEBUG: sign found at location " + s.toString());
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
// Do a quick check to see if this sign location is in
//plugin.getLogger().info("DEBUG: welcome sign");
/**
* Checks to see if a sign has been broken
*
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL)
public void onSignBreak(BlockBreakEvent e) {
Block b = e.getBlock();
Player player = e.getPlayer();
if (Settings.worldName.isEmpty() || Settings.worldName.contains(b.getWorld().getName())) {
if (Tag.SIGNS.isTagged(b.getType())) {
Sign s = (Sign) b.getState();
//plugin.getLogger().info("DEBUG: sign found at location " + s.toString());
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
// Do a quick check to see if this sign location is in
//plugin.getLogger().info("DEBUG: welcome sign");
// the list of warp signs
if (warpList.containsValue(s.getLocation())) {
//plugin.getLogger().info("DEBUG: warp sign is in list");
Expand All @@ -92,24 +91,24 @@ public void onSignBreak(BlockBreakEvent e) {
}
}
}
}
}

/**
* Event handler for Sign Changes
*
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onSignWarpCreate(SignChangeEvent e) {
//plugin.getLogger().info("DEBUG: SignChangeEvent called");
String title = e.getLine(0);
Player player = e.getPlayer();
//plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
/**
* Event handler for Sign Changes
*
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL)
public void onSignWarpCreate(SignChangeEvent e) {
//plugin.getLogger().info("DEBUG: SignChangeEvent called");
String title = e.getLine(0);
Player player = e.getPlayer();
//plugin.getLogger().info("DEBUG: The first line of the sign says " + title);
assert title != null;
if (title.equalsIgnoreCase(plugin.myLocale().warpswelcomeLine)) {
//plugin.getLogger().info("DEBUG: Welcome sign detected");
if (!Settings.worldName.isEmpty() && !Settings.worldName.contains(player.getWorld().getName())) {
//plugin.getLogger().info("DEBUG: Incorrect world");
//plugin.getLogger().info("DEBUG: Welcome sign detected");
if (!Settings.worldName.isEmpty() && !Settings.worldName.contains(player.getWorld().getName())) {
//plugin.getLogger().info("DEBUG: Incorrect world");
player.sendMessage(ChatColor.RED + plugin.myLocale().errorWrongWorld);
return;
}
Expand Down Expand Up @@ -148,7 +147,6 @@ public void onSignWarpCreate(SignChangeEvent e) {
// The block is still a sign
//plugin.getLogger().info("DEBUG: The block is still a sign");
Sign oldSign = (Sign) oldSignBlock.getState();
if (oldSign != null) {
//plugin.getLogger().info("DEBUG: Sign block is a sign");
if (oldSign.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
//plugin.getLogger().info("DEBUG: Old sign had a green welcome");
Expand All @@ -157,7 +155,6 @@ public void onSignWarpCreate(SignChangeEvent e) {
player.sendMessage(ChatColor.RED + plugin.myLocale().warpsdeactivate);
removeWarp(player.getUniqueId());
}
}
}
// Set up the warp
if (addWarp(player.getUniqueId(), e.getBlock().getLocation())) {
Expand Down Expand Up @@ -237,18 +234,16 @@ void loadWarpList() {
* @param loc
*/
public boolean addWarp(UUID player, Location loc) {
// Do not allow warps to be in the same location
if (warpList.containsValue(loc)) {
return false;
}
// Remove the old warp if it existed
if (warpList.containsKey(player)) {
warpList.remove(player);
// Do not allow warps to be in the same location
if (warpList.containsValue(loc)) {
return false;
}
// Remove the old warp if it existed
warpList.remove(player);
warpList.put(player, loc);
saveWarpList(true);
return true;
}
warpList.put(player, loc);
saveWarpList(true);
return true;
}

/**
* Removes a warp when the welcome sign is destroyed. Called by
Expand Down
Loading

0 comments on commit 8679b3e

Please sign in to comment.