Skip to content

Commit 190a30e

Browse files
authored
Merge pull request #17 from alexey-va/master
Oops... Forgot to push the last one
2 parents 9e552a0 + c19853f commit 190a30e

10 files changed

Lines changed: 163 additions & 112 deletions

File tree

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<id>spigot-repo</id>
2222
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
2323
</repository>
24-
<repository>
25-
<id>md_5-repo</id>
26-
<url>http://repo.md-5.net/content/groups/public/</url>
27-
</repository>
2824
<repository>
2925
<id>md_5-repo2</id>
3026
<url>https://repo.md-5.net/content/repositories/public/</url>

src/main/java/me/ccrama/Trails/Commands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
9393
if(p.hasPermission("trails.reload")){
9494
plugin.reloadConfig();
9595
plugin.onDisable();
96-
plugin.onEnable();
9796
plugin.onLoad();
97+
plugin.onEnable();
9898
p.sendMessage("Plugin reloaded");
9999
return true;
100100
}

src/main/java/me/ccrama/Trails/Trails.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ public class Trails extends JavaPlugin {
6767
@Override
6868
public void onEnable() {
6969
plugin = this;
70-
71-
pm = Bukkit.getServer().getPluginManager();
72-
// Activate plugin config
73-
this.config = new Config(this);
74-
this.language = new Language(this);
7570
// Wrapper for custom bukkit events
7671
//this.blockData = new BlockDataManager(this);
7772
this.toggle = new ToggleLists(this);
@@ -99,23 +94,19 @@ public void onEnable() {
9994
this.commands = new Commands(this);
10095
RegisterCommands();
10196
// Towny hook
102-
if (pm.getPlugin("Towny") != null) {
97+
if (pm.getPlugin("Towny") != null && townyHook == null) {
10398
townyHook = new TownyHook(this);
10499
}
105-
// Lands Hook
106-
if (pm.getPlugin("Lands") != null) {
107-
landsHook = new LandsAPIHook(this);
108-
}
109100
// GriefPrevention Hook
110-
if (pm.getPlugin("GriefPrevention") != null) {
101+
if (pm.getPlugin("GriefPrevention") != null && gpHook == null) {
111102
gpHook = new GriefPreventionHook(this);
112103
}
113104
// LogBlock Hook
114-
if(pm.getPlugin("LogBlock") != null && config.logBlock) {
105+
if(pm.getPlugin("LogBlock") != null && config.logBlock && lbHook == null) {
115106
lbHook = new LogBlockHook(this);
116107
}
117108
// CoreProtect Hook
118-
if(pm.getPlugin("CoreProtect") != null && config.coreProtect) {
109+
if(pm.getPlugin("CoreProtect") != null && config.coreProtect && cpHook == null) {
119110
cpHook = new CoreProtectHook(this);
120111
}
121112
// PlaceholderAPI Support
@@ -131,13 +122,20 @@ public void onEnable() {
131122

132123
@Override
133124
public void onLoad() {
125+
pm = Bukkit.getServer().getPluginManager();
126+
this.config = new Config(this);
127+
this.language = new Language(this);
134128
// Worldguard Hook
135-
if (Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null && getConfig().getBoolean("Plugin-Integration.WorldGuard.IntegrationEnabled", true)) {
129+
if (pm.getPlugin("WorldGuard") != null && getConfig().getBoolean("Plugin-Integration.WorldGuard.IntegrationEnabled", true) && wgHook == null) {
136130
wgHook = new WorldGuardHook(this);
137131
this.messagePlayers = new ArrayList<UUID>();
138132
Console.sendConsoleMessage(String.format(ChatColor.GRAY + "[" + ChatColor.YELLOW + "Trails" + ChatColor.GRAY + "]"
139133
+ ChatColor.GREEN + " hooked into worldguard! Flag trails-flag registered. Set trails-flag = DENY to deny trails in regions."));
140134
}
135+
// Lands Hook
136+
if (pm.getPlugin("Lands") != null && landsHook == null) {
137+
landsHook = new LandsAPIHook(this);
138+
}
141139
}
142140

143141
/**

src/main/java/me/ccrama/Trails/compatibility/LandsAPIHook.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.Bukkit;
77
import org.bukkit.ChatColor;
88
import org.bukkit.Location;
9+
import org.bukkit.Material;
910
import org.bukkit.entity.Player;
1011
import org.bukkit.inventory.ItemStack;
1112

@@ -22,20 +23,20 @@ public class LandsAPIHook
2223
private final LandsIntegration landsIntegration;
2324
private final RoleFlag roleflag;
2425
private Trails plugin;
26+
private ItemStack icon;
2527

2628
public LandsAPIHook(Trails plugin) {
2729
this.plugin = plugin;
30+
icon = new ItemStack(plugin.getLanguage().material, 1);
2831
this.landsIntegration = new LandsIntegration(plugin);
2932
//seems like should use RoleFlag instead of LandFlag
30-
this.roleflag = (RoleFlag) new RoleFlag(plugin, Category.ACTION, "ALLOW_TRAILS", plugin.getConfigManager().applyInSubAreas, plugin.getConfigManager().landsPathsWilderness);
33+
this.roleflag = new RoleFlag(plugin, Category.ACTION, "ALLOW_TRAILS", plugin.getConfigManager().applyInSubAreas, plugin.getConfigManager().landsPathsWilderness);
3134
roleflag.setDisplayName(plugin.getLanguage().displayName);
32-
roleflag.setIcon(new ItemStack(plugin.getLanguage().material));
35+
roleflag.setIcon(icon);
3336
roleflag.setDescription(plugin.getLanguage().description);
3437
roleflag.setDisplay(true);
35-
Bukkit.getServer().getConsoleSender().sendMessage(plugin.getCommands().getFormattedMessage(Bukkit.getConsoleSender().getName(),
36-
(plugin.getLanguage().pluginPrefix + ChatColor.GREEN + " hooked into " + ChatColor.YELLOW + "Lands!")));
37-
Bukkit.getServer().getConsoleSender().sendMessage(plugin.getCommands().getFormattedMessage(Bukkit.getConsoleSender().getName(),
38-
(plugin.getLanguage().pluginPrefix + ChatColor.YELLOW + " ALLOW_TRAILS " + ChatColor.GREEN + "Role Flag registered!")));
38+
plugin.getLogger().info(plugin.getLanguage().pluginPrefix + ChatColor.GREEN + " hooked into " + ChatColor.YELLOW + "Lands!");
39+
plugin.getLogger().info(plugin.getLanguage().pluginPrefix + ChatColor.YELLOW + " ALLOW_TRAILS " + ChatColor.GREEN + "Role Flag registered!");
3940
landsIntegration.registerFlag(roleflag);
4041
}
4142

src/main/java/me/ccrama/Trails/configs/Config.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ public Config(Trails plugin) {
4646
private void loadConfig(Trails plugin) {
4747

4848
// Plugin Integrations
49-
townyPathsWilderness = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.Towny.PathsInWilderness"));
50-
townyPathsPerm = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.Towny.TownyPathsPerm"));
51-
landsPathsWilderness = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.Lands.PathsInWilderness"));
52-
gpPathsWilderness = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.GriefPrevention.PathsInWilderness"));
53-
applyInSubAreas = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.Lands.ApplyInSubAreas"));
54-
logBlock = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.LogBlock.LogPathBlocks"));
55-
logBlock = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.CoreProtect.LogPathBlocks"));
56-
checkBypass = Boolean.valueOf(plugin.getConfig().getString("Plugin-Integration.WorldGuard.CheckBypass"));
57-
sendDenyMessage = Boolean.valueOf(plugin.getConfig().getString("Messages.SendDenyMessage"));
49+
townyPathsWilderness = plugin.getConfig().getBoolean("Plugin-Integration.Towny.PathsInWilderness");
50+
townyPathsPerm = plugin.getConfig().getBoolean("Plugin-Integration.Towny.TownyPathsPerm");
51+
landsPathsWilderness = plugin.getConfig().getBoolean("Plugin-Integration.Lands.PathsInWilderness");
52+
gpPathsWilderness = plugin.getConfig().getBoolean("Plugin-Integration.GriefPrevention.PathsInWilderness");
53+
applyInSubAreas = plugin.getConfig().getBoolean("Plugin-Integration.Lands.ApplyInSubAreas");
54+
logBlock = plugin.getConfig().getBoolean("Plugin-Integration.LogBlock.LogPathBlocks");
55+
logBlock = plugin.getConfig().getBoolean("Plugin-Integration.CoreProtect.LogPathBlocks");
56+
checkBypass = plugin.getConfig().getBoolean("Plugin-Integration.WorldGuard.CheckBypass");
57+
sendDenyMessage = plugin.getConfig().getBoolean("Messages.SendDenyMessage");
5858
messageInterval = plugin.getConfig().getInt("Messages.Interval");
5959
langType = plugin.getConfig().getString("General.Language");
60-
sneakBypass = plugin.getConfig().getBoolean("General.Sneak-Bypass", true);
61-
runModifier = plugin.getConfig().getDouble("General.Run-Modifier", 1.0);
62-
speedBoostInterval = plugin.getConfig().getLong("General.Speed-Boost-Interval", 5L);
63-
speedBoostStep = (float)plugin.getConfig().getDouble("General.Speed-Boost-Step", 0.025);
60+
sneakBypass = plugin.getConfig().getBoolean("General.sneak-bypass", true);
61+
runModifier = plugin.getConfig().getDouble("General.run-modifier", 1.0);
62+
speedBoostInterval = plugin.getConfig().getLong("General.speed-boost-interval", 5L);
63+
speedBoostStep = (float)plugin.getConfig().getDouble("General.speed-boost-step", 0.025);
6464
usePermission = plugin.getConfig().getBoolean("General.use-permission-for-trails", false);
6565
usePermissionBoost = plugin.getConfig().getBoolean("General.use-permission-for-boost", false);
66-
onlyTrails = plugin.getConfig().getBoolean("General.Speed-Boost-Only-Trails", true);
66+
onlyTrails = plugin.getConfig().getBoolean("General.speed-boost-only-trails", true);
6767
immediatelyRemoveBoost = plugin.getConfig().getBoolean("General.immediately-remove-boost", false);
68-
enabledWorlds = (ArrayList<String>) plugin.getConfig().getList("General.Enabled-Worlds", new ArrayList<>());
68+
enabledWorlds = (ArrayList<String>) plugin.getConfig().getList("General.enabled-worlds", new ArrayList<>());
6969
saveInterval = plugin.getConfig().getInt("Data-Saving.Interval");
7070
enabledDefault = plugin.getConfig().getBoolean("General.enabled-by-default", true);
7171
boostEnabledDefault = plugin.getConfig().getBoolean("General.boost-enabled-by-default", true);

src/main/java/me/ccrama/Trails/configs/Language.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.util.ArrayList;
56
import java.util.List;
67
import org.bukkit.Bukkit;
78
import org.bukkit.Material;
@@ -13,6 +14,7 @@
1314

1415
public class Language
1516
{
17+
public String alreadyMaxLevel = "%plugin_prefix% &fYour &eTrail &fis already max level!";
1618
private File languageFile;
1719
private FileConfiguration language;
1820
private File languageFolder;
@@ -92,9 +94,15 @@ public void loadLanguageFile(File languageFile){
9294
notPlayedBefore = language.getString("messages.notPlayedBefore");
9395
cantCreateTrails = language.getString("messages.cantCreateTrails");
9496
saveMessage = language.getString("messages.saveMessage");
95-
material = Material.matchMaterial(language.getString("lands.flag.icon-material"));
96-
displayName = language.getString("lands.flag.display-name");
97+
material = Material.matchMaterial(language.getString("lands.flag.icon-material", "DIRT_PATH").toUpperCase());
98+
displayName = ChatColor.translateAlternateColorCodes('&',language.getString("lands.flag.display-name"));
9799
description = language.getStringList("lands.flag.description");
100+
alreadyMaxLevel = language.getString("messages.alreadyMaxLevel");
101+
ArrayList<String> temp = new ArrayList<>();
102+
for(String s : description){
103+
temp.add(ChatColor.translateAlternateColorCodes('&',s));
104+
}
105+
description = temp;
98106
}else {
99107
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[Trails] &cCannot find " + languageFile.getName()));
100108
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[Trails] &cCheck Trails/lang/ folder and make sure that"));

src/main/java/me/ccrama/Trails/listeners/MoveEventListener.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,36 @@ public void walk(PlayerMoveEvent e) {
5757
//System.out.println("Link is 1");
5858
link = links.get(0);
5959
//System.out.println(link.getMat() + " | " + link.getTrailName());
60-
} else if(links != null) {
60+
} else if (links != null) {
6161
//System.out.println("Link amount > 1");
6262
container = new CustomBlockData(block, main);
63-
String[] blockTrailName = container.get(trailNameKey, PersistentDataType.STRING).split(":");
64-
Integer id = null;
65-
try{
66-
id = Integer.parseInt(blockTrailName[1]);
67-
} catch (Exception ignored){}
68-
for (Link lnk : links) {
69-
Integer closestId = null;
70-
if (lnk.getTrailName().equals(blockTrailName[0])) {
71-
//System.out.println("Link was found!");
72-
if((id == null || lnk.identifier() == id) || (link == null && lnk.identifier() > id)){
73-
link = lnk;
74-
break;
63+
if (!container.has(trailNameKey, PersistentDataType.STRING)) {
64+
Link minLink = null;
65+
for (Link link1 : links) {
66+
if (minLink == null || link1.identifier() < minLink.identifier()) minLink = link1;
67+
}
68+
link = minLink;
69+
} else {
70+
String[] blockTrailName = container.get(trailNameKey, PersistentDataType.STRING).split(":");
71+
Integer id = null;
72+
try {
73+
id = Integer.parseInt(blockTrailName[1]);
74+
} catch (Exception ignored) {
75+
}
76+
link = links.get(0);
77+
for (Link lnk : links) {
78+
if (lnk.getTrailName().equals(blockTrailName[0])) {
79+
if (id != null && lnk.identifier() == id) {
80+
link = lnk;
81+
break;
82+
}
83+
if (lnk.identifier() < link.identifier()) link = lnk;
7584
}
76-
else if(link != null && lnk.identifier() > id) break;
77-
else link = lnk;
7885
}
7986
}
8087
}
8188
Player p = e.getPlayer();
82-
System.out.println(p.getWalkSpeed());
89+
//System.out.println(p.getWalkSpeed());
8390

8491
//System.out.println(p.getWalkSpeed());
8592

@@ -119,7 +126,7 @@ public void run() {
119126
for (Map.Entry<UUID, Booster> entry : speedBoostedPlayers.entrySet()) {
120127
Player player = entry.getValue().getPlayer();
121128
//System.out.println("boosting: "+player);
122-
if(entry.getValue().immediately) player.setWalkSpeed(entry.getValue().targetSpeed);
129+
if (entry.getValue().immediately) player.setWalkSpeed(entry.getValue().targetSpeed);
123130
else if (entry.getValue().getTargetSpeed() > player.getWalkSpeed())
124131
player.setWalkSpeed(Math.min(player.getWalkSpeed() + main.getConfigManager().speedBoostStep, entry.getValue().getTargetSpeed()));
125132
else
@@ -138,7 +145,6 @@ else if (entry.getValue().getTargetSpeed() > player.getWalkSpeed())
138145
}
139146

140147
if ((main.getConfigManager().sneakBypass && e.getPlayer().isSneaking()) || link == null) return;
141-
//System.out.println("asd");
142148
if ((!main.getConfigManager().usePermission && main.getToggles().isDisabled(p.getUniqueId().toString())) || (main.getConfigManager().usePermission && !p.hasPermission("trails.create-trails"))) {
143149
return;
144150
}
@@ -214,9 +220,9 @@ private void makePath(Player p, Block block, Link link) {
214220
Integer walked = container.get(walksKey, PersistentDataType.INTEGER);
215221
if (walked == null) walked = 0;
216222
//System.out.println(walked);
217-
if (walked >= link.decayNumber()) {
223+
if (walked >= link.decayNumber() && link.getNext() != null) {
218224
container.set(walksKey, PersistentDataType.INTEGER, 0);
219-
container.set(trailNameKey, PersistentDataType.STRING, link.getTrailName()+":"+link.identifier());
225+
container.set(trailNameKey, PersistentDataType.STRING, link.getTrailName() + ":" + link.getNext().identifier());
220226
try {
221227
this.changeNext(p, block, link);
222228
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {

0 commit comments

Comments
 (0)